【问题标题】:Code::Blocks Compilation ErrorsCode::Blocks 编译错误
【发布时间】:2012-02-22 22:10:30
【问题描述】:

我在使用 Code::Blocks 时遇到了一些问题,这是编译后 / 时的输出;

3|iostream: No such file or directory|
4|error: syntax error before "namespace"|
|In function `main':|
8|error: `cout' undeclared (first use in this function)|
8|error: (Each undeclared identifier is reported only once|
8|error: for each function it appears in.)|
||=== Build finished: 5 errors, 1 warnings ===|

我的代码如下;

// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

【问题讨论】:

  • 这不会解决问题,但你应该说using namespace std;,虽然不建议这样做。
  • 你确定你已经创建了 C++ 控制台项目吗?
  • 我该怎么做? (我是一个完整的新手)我只是做了空白项目?
  • 文件 -> 新项目 -> 控制台应用程序 -> C++
  • Michal,将其发布为答案,因为它解决了我的问题!

标签: c++ compilation mingw codeblocks


【解决方案1】:

您必须创建控制台 C++ 项目。

文件 -> 新项目 -> 控制台应用程序 -> C++ 。

它将设置变量和链接器选项,如基础库。

【讨论】:

    【解决方案2】:

    cout 问题是因为你应该说

    using namespace std;
    

    iostreams 的问题可能是您需要在工具链中设置 MINGW 的路径。您可以从 Settings->Compiler and debugger settings->Global compiler setting->toolchain executables menus/tabs 访问它。在这里选择安装了 MINGW 的部分并且应该处理它。

    【讨论】:

    • 我的代码确实有使用,但由于某种原因,它在复制和粘贴时被删除,我将对其进行编辑。谢谢指点!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 2011-08-02
    • 1970-01-01
    相关资源
    最近更新 更多