使用“std”的标准惯例 [英] Standard convention for using "std"
本文介绍了使用“std”的标准惯例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Exact Duplicate: Do you prefer explicit namespaces or ‘using’ in C++?
using namespace std;
或
using std::cin;
using std::cout;
或
std::cout<<"Hello World!"<<std::endl;
推荐答案
此处。
第一种风格,即使用命名空间,而不是命名空间的整个目的。除非在小代码片段中,否则不应该使用它。 (我不使用它那里!:D)
The first style i.e. using namespace whatever defeats the whole purpose of namespacing. You should never be using it except in small code snippets. (I don't use it there either! :D )
第二个是太冗长。不实用。
Second one is way too verbose. Not practical.
我个人喜欢第三种风格,即输出完全限定的名称(例如std :: cout)。
I personally like the third style i.e. typing out the fully qualified name (e.g. std::cout).
记住,代码读取的次数比它写的次数多。使用完全限定名称IMO使您的代码更可读。
Remember, the code is read much more times than it is written & using fully qualified names IMO makes your code more readable.
这篇关于使用“std”的标准惯例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文