visual-studio C++ Visual Studios:无法打开包含文件......嗯?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3375380/
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-10-22 12:17:10  来源:igfitidea点击:

C++ Visual Studios : can not open include file ... eh?

visual-studiovisual-c++

提问by JnBrymn

Sorry for posting such a lowly beginner's question, but I just still don't know my way around Visual Studios yet. I'm trying to compile a code in C++ Visual Studios:

很抱歉发布了如此低级的初学者问题,但我仍然不知道如何使用 Visual Studios。我正在尝试在 C++ Visual Studios 中编译代码:

#include "Banana.h"

int main(int argc, char* argv[])
{
    fruit::Banana banana;
    banana.dance();
    return 0;
}

and I'm getting an error

我收到一个错误

fatal error C1083: Cannot open include file: 'Banana.h': No such file or directory

致命错误 C1083:无法打开包含文件:'Banana.h':没有这样的文件或目录

But in the Solution Explorer under the project that I'm working with there is a source folder labeled "fruit/Header Files" and within that folder is "Banana.h". I thought that everything in the source folders within the same project were automatically on the source path. What gives?

但是在我正在处理的项目下的解决方案资源管理器中,有一个标记为“fruit/Header Files”的源文件夹,该文件夹内是“Banana.h”。我认为同一项目中源文件夹中的所有内容都自动位于源路径上。是什么赋予了?

回答by Mark Ransom

You will need to configure additional include paths. If you go to the Project Properties, you'll find it under Configuration Properties, C/C++at the top.

您将需要配置额外的包含路径。如果你去到项目属性,你会发现它下Configuration PropertiesC/C++在顶部。

回答by David Thornley

The Solution Explorer doesn't show if the .h files are actually usable. Whether a header file is usable depends on whether it's reachable, which is determined by the list of directories to include from. I think the solution includes header files so it knows to recompile if they change.

解决方案资源管理器不会显示 .h 文件是否实际可用。头文件是否可用取决于它是否可达,这由要包含的目录列表决定。我认为该解决方案包含头文件,因此它知道如果它们发生变化就重新编译。

回答by Alexander Gessler

Right-click on the tab header of the source code file and choose open file location. Then, start there and try to locate the Banana.hfile and move it either to the same directory (and re-add it to the solution), or change the #includeline accordingly. You could also add the directory where Banana.his located to the list of include paths (project settings -> c++ -> include directories).

右键单击源代码文件的选项卡标题并选择open file location. 然后,从那里开始并尝试找到该Banana.h文件并将其移动到同一目录(并将其重新添加到解决方案中),或相应地更改该#include行。您还可以将所在的目录添加Banana.h到包含路径 ( project settings -> c++ -> include directories)列表中。

回答by Puppy

It's very confusing, because the Solution Manager uses virtual filepaths, whereas #include uses real filepaths. This way, you can make filters in SM and have no disk change, and add files that you can't include, etc.

这非常令人困惑,因为解决方案管理器使用虚拟文件路径,而 #include 使用真实文件路径。这样,您可以在 SM 中制作过滤器而无需更改磁盘,并添加您无法包含的文件等。