Why do we use `#include "stdafx.h"` instead of `#include <stdafx.h>`?

Sepideh Abadpour picture Sepideh Abadpour · May 16, 2016 · Viewed 17.6k times · Source

From here, it is said that:

For #include "filename" the preprocessor searches in the same directory as the file containing the directive. This method is normally used to include programmer-defined header files.

For #include <filename> the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

While this wiki link suggests that stdafx.h is an header file pre-designed by visual studio IDE

stdafx.h is a file, generated by Microsoft Visual Studio IDE wizards, that describes both standard system and project specific include files that are used frequently but hardly ever change.

Compatible compilers (for example, Visual C++ 6.0 and newer) will precompile this file to reduce overall compile times. Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.

The AFX in stdafx.h stands for Application Framework eXtensions. AFX was the original abbreviation for the Microsoft Foundation Classes (MFC). While the name stdafx.h is used by default, projects may specify an alternative name.

Then

Why do we use #include "stdafx.h" instead of #include <stdafx.h> ?

Answer

Edward Strange picture Edward Strange · May 16, 2016

A stdafx.h, stdafx.cpp pair is generated by VS from a template. It resides in the same directory the rest of the files end up. You will probably end up altering it specifically for your project. So we use "" instead of <> for exactly the reason that it's in the same directory as your first quote describes.