预编译头文件的行为导致错误 [英] Behaviour of precompiled header file causes error
问题描述
在下面的简单程序中,
#include<conio.h>
#include "stdafx.h"
#include<stdio.h>
int main(int argc, _TCHAR* argv[])
{
printf("print");
getch();
return 0;
}
给出错误提示1>e:\cust\a\a\a.cpp(14) : error C3861: 'getch': identifier not found
我正在使用VS2005.我知道"stdafx.h"是预编译的头文件,但是为什么我们不应该在其之前添加任何头文件?
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?
推荐答案
VS中的预编译头以这种方式工作,即预编译头(通常命名为stdafx.h
)必须是包含文件中的第一个头.甚至更多
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"
应该是源代码中的第一件事,因为MSDN说:编译器将.h文件之前发生的所有代码都视为已预编译.它跳到与.h文件关联的#include指令之后,使用其中包含的代码在.pch文件中,然后编译文件名之后的所有代码..
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. ".
这篇关于预编译头文件的行为导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!