71
votes

I am trying to compile a simple VS program in C++ as an assignment for class. We only ever include <iostream> and I keep getting this error:

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

My program is literally this small...

#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. Really I would love to start an empty project instead of installing with all these files predefined, I think it would make it a lot easier but I never get that option when creating a project. Anybody have any suggestions?

5
You need to turn off the use of precompiled headers in your project's settings (you can also uncheck Use Precompiled Headers when creating new projects in the future.)user168715
How do I go about turning this off for future projects?Howdy_McGee
Please improve your question title. It does not describe the question very will, but instead lists technologies (which is what tags are for).Lightness Races in Orbit
I got Project Properties, but I do not see precompiled Headers. It is in langauge properties?Howdy_McGee
Look under C/C++ -> Precompiled Headers.user168715

5 Answers

101
votes

You can always disable the use of pre-compiled headers in the project settings.

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

Select your project, use the "Project -> Properties" menu and go to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option.


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

9
votes

You can create an empty project by selecting the "Empty Project" from the "General" group of Visual C++ projects (maybe that project template isn't included in Express?).

To fix the problem in the project you already have, open the project properties and navigate to:

Configuration Properties | C/C++ | Precompiled Headers

And choose "Not using Precompiled Headers" for the "Precompiled Header" option.

5
votes

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

If there are no stdafx* files in your project, you need to go to this file's options and set it as “Not using precompiled headers”.

-1
votes

try to add #include "stdafx.h" before #include "iostream"

-1
votes

Right click project solution

Properties -> Configuration Properties -> C/C++ -> Precompiled Headers

  1. Click on "Precompiled Headers" change to "Not Using Precompiled Headers".

  2. Erase the "pch.h"/"stdafx.h" field in "Precompiled Header File" for the EOF error at the end of the build for the project.

  3. Then you can feel free to delete the pch./stdafx. files in your project