Why is std:: used by experienced coders rather than using namespace std;?(为什么有经验的编码人员使用 std:: 而不是使用命名空间 std;?)
问题描述
可能重复:
为什么'使用命名空间std;'在 C++ 中被认为是一种不好的做法?
前几天我问了一个问题,有人回答说如果有人问问题,请向他们展示正确的方法,而不是 using namespace std; 我认为这有点奇怪,因为using 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 stdin my code?
可能不会.
人们不喜欢在上面输入 std::一遍又一遍,他们发现using namespace std 让编译器看到任何 std 名称,即使不合格.这美中不足的是它让编译器看到 any 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-标准#using-namespace-std
这篇关于为什么有经验的编码人员使用 std:: 而不是使用命名空间 std;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么有经验的编码人员使用 std:: 而不是使用命名空间 std;?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
