Error C1083: Cannot Open Include File: 'Stdafx.H'

Error C1083: Cannot open include file: 'stdafx.h'

You have to properly understand what is a "stdafx.h", aka precompiled header. Other questions or Wikipedia will answer that. In many cases a precompiled header can be avoided, especially if your project is small and with few dependencies. In your case, as you probably started from a template project, it was used to include Windows.h only for the _TCHAR macro.

Then, precompiled header is usually a per-project file in Visual Studio world, so:

  1. Ensure you have the file "stdafx.h" in your project. If you don't (e.g. you removed it) just create a new temporary project and copy the default one from there;
  2. Change the #include <stdafx.h> to #include "stdafx.h". It is supposed to be a project local file, not to be resolved in include directories.

Secondly: it's inadvisable to include the precompiled header in your own headers, to not clutter namespace of other source that can use your code as a library, so completely remove its inclusion in vector.h.

Error C1083: Cannot open include file: 'stdafx.h', but it should?

Try #include "stdafx.h".

This will change the way the compiler looks for the header - namely, it will check the local directory.

Here is the SO question for further reference.

error C1083: Cannot open include file: 'stdafx.h': No such file or directory in VS 2005

Fall in the pit of success by using an appropriate project template. Which is Win32 + Win32 Project, don't tick the "Empty project" option on the property page. You'll get pre-generated code for a Win32 application, take a look at it since you might want to keep parts of it. Or just delete it all past the #include for stdafx.h and replace it with the code you want to try. The stdafx.h file is already pre-cooked for you.

The second snippet probably fails to compile because the code sample is not using Unicode strings. Put an L in front of the string literal, like L"\tHello world".

cannot open source file stdafx.h

Visual Studio uses it for "precompiled headers" feature. If you are not experienced with Visual Studio, I would recommend to keep the stdafx.h in the project.

And of course, if you #include it, you ought to have it.



Related Topics



Leave a reply



Submit