您的位置:首页 > 运维架构

error: `cout' was not declared in this scope

2016-05-22 21:44 726 查看
Linux下C++使用GCC编译出错:

程序:

#include<iostream>

int main()

{
cout << "Hello World!" << endl;

return 0;

}

编译出错:

$ g++ s.cpp -o s.out

s.cpp: In function `int main(int, char**)':
 
s.cpp:12: error: `cout' was not declared in this scope
s.cpp:12: error: `endl' was not declared in this scope

原因:
C++ 1998 要求cout and endl被调用使用'std::cout'和'std::endl'格式,或using namespace std;

修改后:
#include<iostream>
int main()
{

std::cout <<

"Hello World!" << std::endl;

return 0;

}


#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world" << endl;

return 0;

}

编译通过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c c++ gcc linux c语言