linux c++之using namespace std

#include <iostream.h>
int main()
{
     double a;
     a=3.14159265;
     cout<<"a= "<<a<<endl;
     return 0;
}
以上是在windows下面一个c++文件的源码,但是拿到linux下面,编译的时候就有问题了,
 g++ -Wall -o float float.cpp
float.cpp:1:22: error: iostream.h: 没有那个文件或目录
float.cpp: In function ‘int main()’:
float.cpp:6: error: ‘cout’ was not declared in this scope
float.cpp:6: error: ‘endl’ was not declared in this scope
这就是上面的提示,根据提示,修改为一下的代码:
#include <iostream>
using namespace std;
int main()
{
     double a;
     a=3.14159265;
     cout<<"a= "<<a<<endl;
     return 0;
}
就能进行编译了,问题解决
分析原因:This is becuase C++ 1998 requires cout and endl be called 'std::cout' and 'std::endl', or that a proper using directives such as 'using namespace std;' be used.

作者: yuzhou133   发布时间: 2010-11-25