我在许多地方看到下面的语法,即在使用STL类时未明确限定其名称空间为std::
。那么初始的namespace std {}
有什么优点呢?为什么不能只使用using namespace std;
?
namespace std {}
using namespace std;
我在许多地方看到下面的语法,即在使用STL类时未明确限定其名称空间为std::
。那么初始的namespace std {}
有什么优点呢?为什么不能只使用using namespace std;
?
namespace std {}
using namespace std;
namespace std {}
仅仅是声明了一个命名空间,这样编译器就知道它的存在了,而使用 using namespace std;
就不会导致出错。
稍后在代码中,从 std::
中提取的内容可以被 #include
进来,并且它们可以自动地被引用而不需要前缀 std::
。