i am trying to compile it (ms visual c++) but it is not compiling, i guess there is some errors but visual c++ is only saying fatal error which i have no idea what it is.Any idea?

#include "stdafx.h"
#include <iostream>
using namespace std;
      int nbs=0;
   
      void Queens(int nn, int row[], int k=0)
   
      { if(k==nn)
   
      { cout<<endl<<"Solution "<<(++nbs)<<":"<<endl;
   
      for(int i=0; i<nn; i++)
   
      { for(int j=0; j<nn;j++)
   
      { if(row[i]==j) cout<<("Q "); else cout<<(". ");
   
      } cout<<endl;} cout<<endl;}
   
      else
  
      { for(int i=0; i<nn; i++)
  
      { row[k]=i;
  
      for(int j=0; j<k;j++)
  
      { if((row[j]==row[k])||((row[j]-row[k])==(k-j))
  
      ||((row[k]-row[j])==(k-j))) goto fails;
  
      } Queens(nn, row, k+1); fails:;}}
  
      }
  
      int qu_main(int argc, char *argv[])
  
      { const int nn = 8;
  
      int *row = new int[nn];
  
      Queens(nn, row);
  
      return 0;
  
      }

Dani AI

Generated

Brief, practical diagnosis and fixes for the Visual C++ "fatal error" scenario discussed by and .

Visual Studio project templates frequently enable precompiled headers. When a translation unit does not match the project PCH settings the compiler aborts with a fatal include-related error (commonly about stdafx.h). Two robust options: disable precompiled headers for the project or keep PCH and add the required PCH files correctly. To disable PCH: open Project Properties -> C/C++ -> Precompiled Headers and set it to "Not Using Precompiled Headers" (this can be applied per-file via the file Properties if only some sources need the change). To keep PCH, ensure one source generates the PCH and that the required header is actually present and included as the first header. See Microsofts guidance on .

Another common cause of link-time failure is an incorrect entry point. Console programs need a proper main (or wmain) signature; a differently named function will produce unresolved-main linker messages. If a different entry point is intentional, set the linker entry point explicitly under Linker -> Advanced -> Entry Point.

Additional practical notes: prefer RAII-friendly containers (for example, std::vector) over manual new/delete for safer memory handling; raise the warning level (e.g., /W4) to catch suspicious constructs early; use the Error List or the full compiler output to copy the exact error text when troubleshooting. Creating an "Empty Project" or turning off precompiled headers when starting small exercises avoids this class of problems altogether.

Recommended Answers

All 5 Replies

well i got it running. i deleted the #include "stdafx.h" and changed qu_main(argc, argv) to int main()

#include "stdafx.h" is mendetory if you are debugging with microsoft visual studio but yes if you are using other debugger such as venus then you dont need that.BTW yeah it ran after i changed it to int main().. thank you a lot.

i use windows and when you create a new win 32 app all you have to do is tell it not to precomplie the headers and use an empty project. this way you get and empty project and can do whatever you want. i never use stdafx.h unless i need it.

Hats off to you boss but i guess that is not my cup of tea .. i am happy with visual studio :)

i use windows and when you create a new win 32 app all you have to do is tell it not to precomplie the headers and use an empty project. this way you get and empty project and can do whatever you want. i never use stdafx.h unless i need it.

sorry i used the wrong word. i use Microsoft visual studio professional 2005 and you can write win 32 console apps without using stdafx.h all you have to tell it is to make an empty project and not to use the precompiled headers. its more of a matter that i want total control and not that there is anything wrong with what they give you to start with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.