本文主要是介绍error: `cout' was not declared in this scope,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Linux下C++编译出错原因解析
程序:
#include
int main()
{
cout << "hello world" << endl;
}
编译出错:
$ g++ s.cpp -o s.out
s.cpp: In function `int main(int, char**)':
s.cpp:12: error: `endl' was not declared in this scope
原因:
C++ 1998 要求cout and endl被调用使用'std::cout'和'std::endl'格式,或using namespace std;
修改后:
#include
int main()
{
std::cout << "hello world" << std::endl;
}
或
#include
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world" << endl;
}
编译通过。
这篇关于error: `cout' was not declared in this scope的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!