Behaviour of precompiled header file causes error

帅比萌擦擦* 提交于 2019-12-13 19:19:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!