问题
In below simple program,
#include<conio.h>
#include "stdafx.h"
#include<stdio.h>
int main(int argc, _TCHAR* argv[])
{
printf("print");
getch();
return 0;
}
gives error saying 1>e:\cust\a\a\a.cpp(14) : error C3861: 'getch': identifier not found
I am using VS 2005. I know that "stdafx.h" is pre-compiled header, but why we should not add any header files before it?
回答1:
Precompiled headers in VS work in such a way that the precompiled header (normally named stdafx.h
) has to be the first one in your includes. Even more, the line
#include "stdafx.h"
should be the first thing in your source, since MSDN says "The compiler treats all code occurring before the .h file as precompiled. It skips to just beyond the #include directive associated with the .h file, uses the code contained in the .pch file, and then compiles all code after filename. ".
来源:https://stackoverflow.com/questions/25016806/behaviour-of-precompiled-header-file-causes-error