C++ Netbeans:找不到包含文件 <iostream>,也无法解析标识符 std、cout

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

Netbeans: cannot find include file <iostream>, also, unable to resolve identifier std, cout

c++includeiostream

提问by user2628156

I'm receiving the above errors on all my C++ projects on Netbeans. I also receive cannot find errors for anything else I try to include. Here's what it says when I hold control and hover over it: http://imgur.com/bBF2xuB. One of the projects actually builds and runs just fine, but all the rest fail either with "build failed, exit value 2" or the run fails with "run failed, exit value 127". I have absolutely no idea how to fix this and everything I've looked up to try to solve this hasn't helped. This wasn't a problem a few months ago when I was using Netbeans, and I'm not sure why the problem spontaneously popped up.

我在 Netbeans 上的所有 C++ 项目中都收到上述错误。对于我尝试包含的其他任何内容,我也收到了无法找到的错误。当我控制并悬停在它上面时,它会说:http: //imgur.com/bBF2xuB。其中一个项目实际上构建并运行得很好,但其他所有项目都失败了,要么是“构建失败,退出值 2”,要么是运行失败,“运行失败,退出值 127”。我完全不知道如何解决这个问题,我为解决这个问题而查找的所有内容都没有帮助。几个月前,当我使用 Netbeans 时,这不是问题,我不确定为什么会自发地出现问题。

I just freshly installed Netbeans 8.0 and the latest cygwin version to try to fix this, but to no avail. I'm running Windows 7. Please help, it would be greatly appreciated.

我刚刚安装了 Netbeans 8.0 和最新的 cygwin 版本来尝试解决此问题,但无济于事。我正在运行 Windows 7。请帮助,将不胜感激。

EDIT The highlighted red errors in the attached photo are files/folders that do not actually exist. Could this be the problem, and if so, how can I go about fixing it?

编辑 附加照片中突出显示的红色错误是实际不存在的文件/文件夹。这可能是问题所在,如果是这样,我该如何解决?

EDIT 2 I deleted or changed some of the non-existent file/folder paths in the code assistance tab under the C/C++ tab under the options, this seems to have made some of the errors in the editor go away, but I still cannot build the project (and the errors haven't disappeared on this specific project), and the projects that I created in the past that used to work just fine are building, but I'm still receiving "RUN FAILED exit value 127".

编辑 2 我在选项下的 C/C++ 选项卡下的代码辅助选项卡中删除或更改了一些不存在的文件/文件夹路径,这似乎使编辑器中的一些错误消失了,但我仍然无法构建项目(并且该特定项目中的错误并没有消失),我过去创建的过去工作正常的项目正在构建,但我仍然收到“RUN FAILED exit value 127”。

回答by mydoghasworms

I just had the same experience with Netbeans (8.0.2) not being able to find includes ("Cannot find include file") on Linux.

我刚刚在 Netbeans (8.0.2) 上遇到了同样的经历,无法在 Linux 上找到包含文件(“找不到包含文件”)。

I had to do the following:

我必须执行以下操作:

  1. In the "Build Tools" tab under "C/C++" settings, click "Restore Defaults" to let it rescan for the tools, after which it picked up the paths to all the executables. Select the newly configured toolset as default and/or delete the old one to reduce confusion.
  1. 在“C/C++”设置下的“Build Tools”选项卡中,单击“Restore Defaults”让它重新扫描工具,然后它选择所有可执行文件的路径。选择新配置的工具集作为默认工具集和/或删除旧工具集以减少混淆。

enter image description here

在此处输入图片说明

  1. Under "Code Assistance", make sure the correct tool collection is selected, then click "Reset Settings" and "Apply". This populated all the necessary paths.
  1. 在“代码帮助”下,确保选择了正确的工具集,然后单击“重置设置”和“应用”。这填充了所有必要的路径。

  1. In my project settings, made sure I was using the right (newly discovered) tool collection.
  1. 在我的项目设置中,确保我使用了正确的(新发现的)工具集合。

After this, all the includes were picked up correctly and errors disappeared from the source checking.

在此之后,所有包含的内容都被正确提取,并且错误从源代码检查中消失了。

回答by kelvincer

I also had this problem (Cannot find include file iostream) in NetBeans IDE 8.1. I solved as follows:

我在 NetBeans IDE 8.1 中也遇到了这个问题(找不到包含文件 iostream)。我解决如下:

Project properties -> Build -> C++ Compiler -> Basic Options -> C++ Standard -> C++98 or C++11 or C++14

项目属性 -> Build -> C++ Compiler -> Basic Options -> C++ Standard -> C++98 or C++11 or C++14

This is the window

这是窗户