为什么std ::使用经验的编码器而不是使用命名空间std;? [英] Why is std:: used by experienced coders rather than using namespace std;?

查看:155
本文介绍了为什么std ::使用经验的编码器而不是使用命名空间std;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

有人回答说,如果有人问一个问题,显示他们正确的方式,而不是使用命名空间std; ,我认为是有点奇怪,因为 use namespace std; 更容易,但我想我现在失败了,因为我是一个初学者编码器,你们知道更好。

The other day when I asked a question someone replied saying if someone asks a question, show them the right way to do it instead of using namespace std; which I thought was a bit weird, as using namespace std; is way easier, But I guess I'm failing right now as I am a 'beginner' coder and you guys know better.

所以我想我的问题是:
为什么 std :: 而不是 using namespace std ;

So I guess my question is: Why std:: instead of using namespace std;?

感谢。

推荐答案

>从C ++常见问题:

From C++ FAQ:


我应该使用 using namespace std 我的代码?

Should I use using namespace std in my code?

可能不是。

人们不喜欢键入 std :: 超过
及以上,他们发现
使用命名空间std 允许编译器看到
any std 名称,即使不合格。
在该软件中飞行是它让
编译器看到任何 std 名称,甚至
你没有想过的那些。在
换句话说,它可以创建名称
冲突和歧义。

People don't like typing std:: over and over, and they discover that using namespace std lets the compiler see any std name, even if unqualified. The fly in that ointment is that it lets the compiler see any std name, even the ones you didn't think about. In other words, it can create name conflicts and ambiguities.

https://isocpp.org/wiki/faq/coding-standards#using-namespace-std

这篇关于为什么std ::使用经验的编码器而不是使用命名空间std;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆