编译第一个Linux程序遇到的问题- Hello World!
初学Linux,写好代码后:
#include <iostream>
int Main()
{
cout<<"Hello world";
return 0;
}
使用g++编译报错 ‘cout’ was not declared in this scope
查阅资料后发现,需要加上using namespace std;
因为C++ 1998要求 cout and endl 使用std::cout,std::endl格式,或者在程序开始申明“ using namespace std;”,不然会出现”cout was not declare this in scope“的错误
修改后的代码为:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello world"<<endl;
return 0;
}
编译成功