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
给出错误说1> e:\ cust \ a \ a \ a.cpp(14):错误C3861:'getch':找不到标识符
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 2005.我知道“stdafx.h”是预编译的头文件,但为什么我们不应该在它之前添加任何头文件呢?
1 个解决方案
#1
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
VS中的预编译头工作方式使得预编译头(通常名为stdafx.h)必须是包含中的第一个头。更重要的是,这条线
#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. ".
应该是源代码中的第一件事,因为MSDN说“编译器会将.h文件之前发生的所有代码视为预编译。它跳过与.h文件关联的#include指令之外,使用包含在.h文件中的代码。 pch文件,然后编译文件名后的所有代码。“
#1
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
VS中的预编译头工作方式使得预编译头(通常名为stdafx.h)必须是包含中的第一个头。更重要的是,这条线
#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. ".
应该是源代码中的第一件事,因为MSDN说“编译器会将.h文件之前发生的所有代码视为预编译。它跳过与.h文件关联的#include指令之外,使用包含在.h文件中的代码。 pch文件,然后编译文件名后的所有代码。“