命名空间namespace是个老相识
//正确程序1 #include <iostream> using namespace std; int main( ) { cout<<"hello world!"<<endl; return 0; }
//出问题的程序 #include <iostream> int main( ) { cout<<"hello world!"<<endl; return 0; }
//再一种写法 #include <iostream> int main( ) { std::cout<<"hello world!"<<std::endl; return 0; }
吓人的错误!
//出错的程序 #include <iostream> #include <math.h> using namespace std; class point { public: double x; double y; }; double distance(point p1,point p2) { double d=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); return d; } int main() { point p1= {3,5},p2= {6,9}; cout<<distance(p1,p2); }