using namespace std

来源:互联网 发布:淘宝宝贝排名靠前技巧 编辑:程序博客网 时间:2024/05/22 05:12

using namespace std

在C++编程中使用using namespace std这条指令,就可以在后面的语句中省略std::,不然的话每次使用标准的输入输出函数的时候都要加上std::,例如

#include <iostream>#include "Sales_item.h"int main( ){Sales_item book,note;std::cin >> book>>note;if (book.same_isbn(note)){std::cout << book + note<<std::endl;}else{std::cout << book << std::endl << std::endl;std::cout << note << std::endl;}return 0;}
就可以简单写成

#include <iostream>#include "Sales_item.h"using  namespace std;int main( ){Sales_item book,note;cin >> book>>note;if (book.same_isbn(note)){cout << book + note<<endl;}else{cout << book << endl << endl;cout << note << endl;}return 0;}

是不是轻盈了很多?


0 0
原创粉丝点击