【问题标题】:Error while compiling a C++ program with G++ [closed]使用 G++ 编译 C++ 程序时出错 [关闭]
【发布时间】:2016-06-01 05:33:21
【问题描述】:

v 这是main.cpp:

#include <stdio.h>

using namespace std;

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

要编译它,我进入 cmd 并输入 g++ main.cpp 但它给了我 2 个错误,说 coutendl 都没有声明。我只能想象这是因为它找不到命名空间std 或无法包含&lt;stdio.h&gt;。我将如何进行这项工作?

【问题讨论】:

  • 你应该使用 #include 而不是
  • 你忘了#include &lt;iostream&gt;
  • 我刚学完 C 就开始学习 C++ 时也犯了类似的错误。

标签: c++ gcc compiler-errors g++


【解决方案1】:

您必须包含iostream,而不是stdio.h 才能使用std::coutstd::endl

【讨论】:

  • 有效,但我还不能接受答案(我必须等待 12 分钟)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-02
  • 2010-10-13
  • 1970-01-01
相关资源
最近更新 更多