c++ - Unresolved inclusion 在任何包含文件中

标签 c++ eclipse inclusion

我在使用 Eclipse 运行 Hello World 程序时遇到错误。我已经安装了 MinGW 和 Cygwin,我知道我只需要一个,但我有其他编辑器使用一个而不是另一个。 我检查了 GCC C++ 编译器下的路径和符号,它链接到包含包含文件的目录。但是,我仍然在包含文件中遇到 Unresolved inclusion 错误。我正在使用 Windows 7。我的代码:

#include <iostream>
#include <strings>
using namespace std;

int main()
{

    string yourName;

    cout << "Enter your name: ";
    cin >> yourName;
    cout << "Hello " << yourName << endl;
    return 0;
}

这是详细的错误

Description                         Resource Path                   Location Type
Symbol 'cin' could not be resolved  test.c  /hello_world/src    line 17 Semantic Error
Symbol 'cout' could not be resolved test.c  /hello_world/src    line 16 Semantic Error
Symbol 'cout' could not be resolved test.c  /hello_world/src    line 18 Semantic Error
Symbol 'endl' could not be resolved test.c  /hello_world/src    line 18 Semantic Error
Type 'namespace' could not be resolved  test.c  /hello_world/src    line 10 Semantic Error
Type 'string' could not be resolved test.c  /hello_world/src    line 14 Semantic Error

有什么帮助吗?谢谢

最佳答案

很可能,您已选择创建一个 C 项目,在这种情况下,Eclipse 将您的工具链设置为仅使用 C 编译器。

由于您使用的是 C++,因此您应该创建一个 C++ 项目并创建一个扩展名为 .cpp 的源文件。

您也可以尝试通过调整项目属性中的设置将现有的 C 项目转换为 C++ 项目,但创建一个新项目通常更容易项目并将文件复制过来(特别是因为您似乎刚刚开始,并且没有很大的代码库)。

正如您在下图中看到的,SimpleC 已创建为 C-project - 在那里,您的源代码显示错误(即使我已将其重命名为.cpp)。

SimpleCpp 项目被创建为 C++ 项目 - 在那里,源代码没有显示任何错误。

enter image description here

关于c++ - Unresolved inclusion 在任何包含文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16341475/

相关文章:

c++ - 使用一些 C++ 模板包装器代码将自己陷入 const 角落

android - 使用 XML 翻译的平滑 float 动画

ruby-on-rails - Rails 包含验证

java - Heroku Postgres : Getting started in Eclipse

php - 包含语言文件时的本地文件包含漏洞

python - 使用Python检查列表元素是否是另一个列表中元素的子元素

c++ - 无法连续读取两个不同的文件

c++ - 重载 >> 运算符

c++ - 在 IAR 的 C++ 编译器中使用 Boost

java - 如何将eclipse中创建的java项目添加到github仓库>