C++ Visual Studio 2012 添加新的头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15901285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:52:45  来源:igfitidea点击:

visual studio 2012 adding new header file

c++visual-studio-2012

提问by Nasif Imtiaz Ohi

In Visual Studio 2012 (C++ environment), for a Win32 console application, I need to include a new header file to my project. I tried copying the files in the project's location but that is of no help. The file is iGraphics.hand it is shown in the header files list but does not compile. What should be the correct approach?

在 Visual Studio 2012(C++ 环境)中,对于 Win32 控制台应用程序,我需要在我的项目中包含一个新的头文件。我尝试复制项目位置中的文件,但这没有帮助。该文件是iGraphics.h,它显示在头文件列表中,但不编译。正确的做法应该是什么?

enter image description here

在此处输入图片说明

回答by Luchian Grigore

You should add the path to that header to the additional include directoriesunder C/C++in your project settings. Afterwards, just #include "iGraphics.h"where you need it.

您应该将该标头的路径添加到项目设置中C/C++下的其他包含目录中。之后,就在您需要的地方。#include "iGraphics.h"

Don't just move header files around, and don't add existing headers to your project for no good reason. This way, you can easily change versions by just specifying a different folder.

不要只是移动头文件,也不要无缘无故地将现有的头文件添加到您的项目中。这样,您只需指定不同的文件夹即可轻松更改版本。

回答by Aman Singh

The easiest way to do this is:

最简单的方法是:

  1. Right click on the header file (to be included) in the Solution explorer.
  2. General->"Excluded from the build"
  3. Select "No" from the drop down list
  4. Click "OK".
  1. 右键单击解决方案资源管理器中的头文件(要包含)。
  2. 常规->“从构建中排除”
  3. 从下拉列表中选择“否”
  4. 单击“确定”。

In VS2012, just using '"' instead of '<>' around the header file in include also works.

在 VS2012 中,仅在头文件周围使用 '"' 而不是 '<>' 也可以使用。

回答by Victor Sand

Put the file in the right place in the file system (like you did). Then right-click your project in the solution explorer and use Add > Existing Itemto add it to your project.

将文件放在文件系统中的正确位置(就像您所做的那样)。然后在解决方案资源管理器中右键单击您的项目,并使用添加 > 现有项目将其添加到您的项目中。

If you don't want to move your file (which you probably should not), see Luchian's answer on how to add the include directory to the include folders.

如果您不想移动文件(您可能不应该移动),请参阅 Luchian 关于如何将包含目录添加到包含文件夹的回答。