C++ – MSVC precompiled headers: Which files need to #include “stdafx.h”

cprecompiled-headersvisual c++

Does every file need to #include "stdafx.h" when using precompiled headers? Or do only source files need to include it.

EDIT: Also, my precompiled header file #includes a lot of STL headers. But, in my headers, I sometimes have functions that return std::vector or something like that, so I need to #include <vector> anyway. Is this worse than including stdafx.h? I need to include the definitions for my unit testing framework.

Best Answer

Every source file needs to include it before any non-comment line. Headers do not need to include it, as every source file will include it before any other header.