"unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx." to your source?"

I’m guessing some people might have this problem as I did.

Solution is to add

#include “stdafx.h”

to your main.cpp file with is your source file I believe. Also have it in your BullCowGame.cpp if you don’t already.

The fact that you are receiving this error means that you forgot to check “Empty project” in the “Win32 Application Wizard” (Visual Studio 2015) or “Windows Desktop Wizard” (Visual Studio 2017). It will also happen in Visual Studio 2017 if you select “Windows Console Application” instead of “Empty Project” in the “New Project” dialog.

After the project has been created, you can also get rid of this error by following these instructions:

  • In the Solution Explorer, right-click you project and select “Properties”
  • In the topmost part of the dialog, select “All Configurations” and “All Platforms” on the “Configuration” and “Platform” combo boxes.
  • Go to the tab “Configuration Properties – C/C++ – General” and change “SDL checks” to “No”
  • Go to the tab “Configuration Properties – C/C++ – Precompiled Headers” and change “Precompiled Header” to “Not Using Precompiled Headers”

After doing these steps, you should no longer have to include “stdafx.h” in your source files.

4 Likes

Thank you for this resolution. I noticed that in the newest version of Visual Studio there is no option to create an “Empty Project”

I’ve included a screenshot of what it has when creating a project.

You will find “Empty Project” under Other
I have included a screenshot which may help you find it

Hope you find it

1 Like

when ever I debug my code in Visual Studio and the code runs it starts with the path file where my file containing the Visual Studio code.
I have include the screenshot the above problem

Can anyone please help me through this problem

Privacy & Terms