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

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