Avoiding Precompiled Headers

I am trying to compile a simple VS program in C ++ as an assignment for a class. We just turn it on and I keep getting this error:

1> Assignment.cpp (15): fatal error C1010: unexpected end of file while searching for precompiled header. Have you forgotten to add '#include "StdAfx.h"' to your source?

My program is literally this little ...

 #include <iostream> using namespace std; int main() { unsigned int day = 30; cout << "My Name is John Doe" << endl; cout << "My Major is CS" << endl; cout << "I was born on day " << day << endl; return 0; } 

I just installed Visual Studio Express 2010. In fact, I would like to start an empty project instead of installing all these files with predefined ones, I think that would make it a lot easier, but I never get this option when creating a project. Anyone have any suggestions?

+42
c ++ visual-studio visual-studio-2010
Aug 31 '11 at 18:32
source share
4 answers

You can always disable the use of precompiled headers in the project settings.

Instructions for VS 2010 (should be similar for other versions of VS):

Select a project, use the Project → Properties menu and go to the “Configuration Properties → C / C ++ → Precompiled Headers” section, then change the “Precompiled Header” parameter to “Do Not Use Precompiled Headers”, option.




If you are trying to install a minimal Visual Studio project for simple C ++ command-line programs (for example, those developed in the introductory C ++ programming classes), you can create an empty C ++ project .

+53
Aug 31 '11 at 18:37
source share
— -

You can create an empty project by selecting the "Empty project" from the "General" group of Visual C ++ projects (perhaps the project template is not included in Express?).

To fix a problem in a project that you already have, open the project properties and go to:

 Configuration Properties | C/C++ | Precompiled Headers 

And select "Don't use Precompiled Headers" for the "Precompiled Header" option.

+9
Aug 31 '11 at 18:40
source share

The .cpp file is configured to use a precompiled header, so it must be included first (before iostream). For Visual Studio, this name is usually "stdafx.h".

If your project does not have stdafx * files, you need to go to these file parameters and set it to "Do not use precompiled headers."

+5
Aug 31 '11 at 18:36
source share

try adding #include "stdafx.h" to #include "iostream"

0
Aug 31 '11 at 18:38
source share



All Articles