By definition "Stdafx. h" is a precompiled header.
Precompiled (once compiled it is not necessary to compile it again).
Precompiled header stdafx. h is basically used in Microsoft Visual Studio to allow the compiler to know the files that are compiled and there is no need to compile it from scratch.
For example:
If you are including the Windows header files below
Code:
#include <windows.h>
#include <tchar.h>
int main() { //your code return 0; }
The compiler will always compile these header files from scratch.
But if you include #include "stdafx. h" before this includes, then the compiler will find the compiled header files of the stdafx. h and not compiled from scratch. But if the compiler does not find any compiled header files from stdafx. h, then first it compiles the files and then stores its compiled version in stdafx. h. So it can be used for compilation next time.
Code:
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
int main() { //your code return 0; }
What are its benefits:
- Reduces build time.
- Reduces the unnecessary processing.
So the conclusion:
Use #include "stdafx. h" where you’re really using others
header files (such as Windows header files). Case
otherwise, no need to use stdafx. h. And that’s not
means that you will remove it from your project, but you can
disable this pre-compiled project settings header,
by selecting the file (where you do not need this stdafx. h) and
go to his properties and find under the option "C ++ ->
Precompiled Header and select Use Precompiled Header to...".
That’s it. I hope you understand.