VS项目中非stdafx.h文件目录包含stdafx.h的编译失败的解决方法

来源:互联网 发布:淘宝分期买手机可靠吗 编辑:程序博客网 时间:2024/04/28 05:50
如果stdafx.h和你当前的工程不在一个文件夹下,当你在代码中第一行写下#include "stdafx.h"时,vc编译器会根据编译规则(相关的规则请查看msdn)来区别stdafx.h的位

置,但是其智能感知工具intellisense却不能。所以你的代码即使能够通过编译器,而intellisense却不能感知到,因为它没有利用相同的规则。如果你指定了这个文件的

具体位置,例如"..//stdafx.h",此时intellisene能够正确的感知到,而编译器却找不到,并给出一个错误。因为编译器只认识这样的预定义头文件字符:#include 

"stdafx.h"。

为什么会有如此糟糕的结果呢?微软宣称这是经过精心考虑后设计的。(http://connect.microsoft.com/visualstudio/feedback/details/533605/stdafx-h-cant-be-

parsed-with-intellisense-squiggles-mechanism[^]).

有很多方法绕过编译器的这个“特色”。一般地,你可以用如下形式来分别满足编译器和intellisense,

#include "stdafx.h"      //pre-compiled header for compiler
#include "..//stdafx.h"  //exact location of pre-compiled header for intellisense

或者,你也可以通过project->properties->configuration propertes->c/c++->general->additional include directories,添

加"$(projectdir)",作为默认目录。一般的,如果工程非常大的话,建议你采用这种方法。
0 0
原创粉丝点击