I have a school assignment for C++, and my code is solid but will not compile. We are learning cout, cin, and loops this week, and are creating a simple hello world program. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream> // library file to read from the keyboard, write to screen
usingnamespace std; /* required when multiple files are used
just include this so you get in a good habit! */
int main() // Tells the computer that this is where the code begins
{ // all the code in main must be enclosed in {}
cout << "Hello World " << endl;
/* writes Hello World to the screen.
(pronounced SEE-out.
endl stands for end-of-line */
system("pause"); // holds the window open until the user hits a key
return 0; // ends main and returns 0 (which means no errors)
} // end of main
When I try and compile it I receive this error message:
1 2 3 4 5
1
1> Hello World.cpp
1>Hello World.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>Hello World.cpp(16): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What is StdAfx.h and why is it needed (or asked for). In class we have not run across this, and as far as I know we only need the #include <iostream> to read to and from the console window.
You must have created your Visual Studio project with "use precompiled headers" checkbox on (it's on by default). You can turn it off, on my VS2012, it's Project->Properties->Configuration Properties->C/C++->Precompiled Headers->Precompiler Header "Not using precompiled headers"
I am using VS 2010 C++, because I can't figure out how to create a new project that isn't an app in 2012 (I have Windows 8). How do I change it in 2010?