使用 G++ 编译C++程序时出错

Error while compiling a C++ program with G++

本文关键字:出错 程序 C++ G++ 编译 使用      更新时间:2023-10-16

v 这是main.cpp

#include <stdio.h>
using namespace std;
int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

为了编译它,我进入 cmd 并键入 g++ main.cpp 但它给了我 2 个错误,说coutendl都没有声明。我只能想象这是因为它找不到命名空间std或无法包含<stdio.h>.我将如何做到这一点?

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