Linux下C++编译出错原因解析
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: `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 
int main()
{
std::cout << "hello world" << std::endl;
}
或
#include 
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world" << endl;
}
编译通过。
相关推荐
  bapinggaitianli    2020-06-04  
   小小小石头    2020-05-30  
   滴水穿石点石成金    2020-11-12  
   wanshiyingg    2020-09-29  
   wuShiJingZuo    2020-09-25  
   jiangtie    2020-08-15  
   zhangxiaocc    2020-06-28  
   offbeatmine    2020-06-14  
   websph    2020-06-14  
   learnpy    2020-06-11  
   chouliqingke    2020-06-09  
   追迷梦境    2020-06-07  
   xushxbigbear微信    2020-05-16  
   chenchuang    2020-05-10  
   89467505    2020-05-08  
   playis    2020-05-04  
   ningningmingming    2020-05-01  
   LychieFan    2020-04-30