想象一下下面的源文件:
src/StdAfx.h
src/moresrc/MyFile.cpp在MyFile.cpp中,我需要包含预编译头文件StdAfx.h。
如果我这样做:
#include "../StdAfx.h"然后我将得到编译器错误:
warning C4627: '#include "../stdafx.h"': skipped when looking for precompiled header use
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?所以这不起作用。如果我这样做的话
#include "StdAfx.h"然后编译正确,但是我在Visual Studio 2013中得到了恼人的错误突出显示,看起来像这样:

所以,就像我说的,这是编译的,但它很烦人。
我如何才能包含"StdAfx.h“而不加下划线,但使其可以编译?
发布于 2015-01-16 03:40:38
您可以将$(ProjectDir) (项目根目录)添加到项目选项中的目录列表(C++ ->常规->附加包含目录)。然后,您将能够在includes中指定相对于项目根目录的路径。例如,如果您有utils/a.h,并且想要在foo/bar/b.h中使用它,那么您可以编写#include "utils/a.h"而不是#include "../../utils/a.h"。如果你在项目根目录中有stdafx.h,你可以只在#include "stdafx.h"中包含它。
https://stackoverflow.com/questions/27970325
复制相似问题