gpt4 book ai didi

c++ - 无法编译C++程序

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:34 25 4
gpt4 key购买 nike

这是代码......

#include <iostream>

int main()
{
cout << "WELCOME TO C++ PROGRAMMING";
return 0;
}

当我进入终端并传递命令时..

g++ hello.cpp

它显示...

hello.cpp: In function ‘int main()’:
hello.cpp:4:2: error: ‘cout’ was not declared in this scope
cout << "WELCOME TO C++ PROGRAMMING";
^
hello.cpp:4:2: note: suggested alternative:
In file included from hello.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output

那这是什么原因呢?我该怎么办?

最佳答案

cout位于 std 命名空间中。

#include <iostream>

int main()
{
std::cout << "Welcome";
return 0;
}

关于c++ - 无法编译C++程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30469637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com