C++ 如何解决未解决的包含:<iostream> 在 eclipse 中?

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

How to solve Unresolved inclusion: <iostream> in eclipse?

c++eclipseeclipse-cdthelios

提问by Alaa M.

I built a simple program in eclipse:

我在eclipse中构建了一个简单的程序:

#include <iostream>

using namespace std;
int main()
{
    cout << "TEST" << endl;
    return 0;
}

It worked in Visual Studio and CodeBlocks, but eclipse is acting weird. it says:

它在 Visual Studio 和 CodeBlocks 中工作,但 eclipse 表现得很奇怪。它说:

Unresolved inclusion: <iostream>

Unresolved inclusion: <iostream>

I read here: C++ - Unresolved inclusion: <iostream>

我在这里阅读: C++ - 未解决的包含:<iostream>

and here: Unresolved <iostream> in Eclipse, Ubuntu

在这里:未解决的 <iostream> 在 Eclipse、Ubuntu

and neither of them worked.

他们都没有工作。

Here are screenshots of project properties:

以下是截图project properties

build_settingsgeneral

构建设置一般的

edit:

编辑:

I downloaded MinGWand now i have this under Settings:

我下载了MinGW,现在我有这个Settings

Updated_Settings

更新_设置

How should i proceed? Maybe now i don't need #include <iostream>because it's now included in the project?

我应该如何进行?也许现在我不需要,#include <iostream>因为它现在包含在项目中?

include

包括

I found iostreamunder Includes.

iostreamIncludes.

So i tried deleting #include <iostream>, but when i try to run the program i get: Launch Failed. Binary not found.error:

所以我尝试删除#include <iostream>,但是当我尝试运行该程序时,我得到: Launch Failed. Binary not found.错误:

launch_failed

启动失败

Thanks

谢谢

edit:

编辑:

Seems like if i compile in some other program (say CodeBlocks) and create the exefile, then eclipsecan run it. But it can't build its own exe.

好像如果我在其他程序(比如 CodeBlocks)中编译并创建exe文件,然后eclipse可以运行它。但它不能建立自己的exe.

Why?

为什么?

回答by Bruce Chidester

This answer did not help me either. My issue was solved with the following steps:

这个答案也没有帮助我。我的问题是通过以下步骤解决的:

You might try changing your source files from *.c to *.cpp. This will provoke gcc to think of the files as C++ and search the proper paths. Might need to make small modifications to the Makefile as well, like on the OBJ: line. Instead of:

您可以尝试将源文件从 *.c 更改为 *.cpp。这将促使 gcc 将文件视为 C++ 并搜索正确的路径。可能还需要对 Makefile 进行小的修改,例如在 OBJ: 行上。代替:

OBJS = YourFile.o

OBJS = YourFile.o

try

尝试

OBJS = YourFile.cpp

OBJS = YourFile.cpp

回答by Peng Zup

I've searched for a few hours and tried a lot solutions.

我已经搜索了几个小时并尝试了很多解决方案。

Envirment: windows, Eclipse IDE for C/C++ Developers

环境:windows,面向 C/C++ 开发人员的 Eclipse IDE

Version: Kepler Service Release 2

版本:开普勒服务第 2 版

CDT: 8.3.0

CDT:8.3.0

Following steps works for me:

以下步骤对我有用:

  1. make sure the envirement is clear. => I suggest delete the eclipse and unzip it again from your orginal download.

  2. make sure the workspace is clear. => Delete .metadata folder in your workspace folder.

  3. use valid MinGW. => the one using download tool is slow and I'm not sure which one to select. I suggest download MinGWStudiofrom http://vaultec.mbnet.fi/mingwstudio.phpThis is a IDE tool like eclipse contains a downloaded unzip MinGW. Make sure you download the one plus MinGW compiler which is about 20M. You can use this studio if you want or copy the MinGW folder to C:/if you still prefer eclipse. Copy /MinGW inside /MinGWStudio to C:/.

  4. close your eclipse and reopen it, create a new project, you should able to see MinGW section for new project option, and it will auto map g++, gcc and include files under C:/MinGW folder. Just make sure you copy MinGW folder from MinGWStudio to the root of C:/.

  1. 确保环境清晰。=>我建议删除 eclipse 并从您的原始下载中再次解压缩。

  2. 确保工作区清晰。=>删除工作区文件夹中的 .metadata 文件夹。

  3. 使用有效的 MinGW。=> 使用下载工具的速度很慢,我不确定选择哪个。我建议从http://vaultec.mbnet.fi/mingwstudio.php下载 MinGWStudio这是一个像 eclipse 这样的 IDE 工具,包含一个下载的解压 MinGW。一定要下载一加MinGW编译器,大概20M左右。如果您愿意,可以使用此工作室,或者如果您仍然喜欢 eclipse,则将MinGW 文件夹复制到C:/将 /MinGWStudio 内的 /MinGW 复制到 C:/

  4. 关闭你的 eclipse 并重新打开它,创建一个新项目,你应该能够看到新项目选项的 MinGW 部分,它会自动映射 C:/MinGW 文件夹下的 g++、gcc 和包含文件。只需确保将 MinGW 文件夹从 MinGWStudio 复制到 C:/ 的根目录。

You will able to see your include after these steps.

在这些步骤之后,您将能够看到您的包含。

includes_screen_cast

include_screen_cast

回答by BlueTechM

right click your project click properties goto C/C++ Build > settings click on Misc. under GCC C++ Compiler and the other flags code should have this after it -std=c++11 then go to Misc. under GCC C Compiler and add this to the other flags code -std=gnu11 apply save your project build your project and it should work

右键单击您的项目单击属性转到 C/C++ 构建 > 设置单击 Misc。在 GCC C++ Compiler 下,其他标志代码应该在 -std=c++11 之后有这个,然后转到 Misc。在 GCC C 编译器下并将其添加到其他标志代码 -std=gnu11 apply 保存您的项目构建您的项目,它应该可以工作