using namespace&using

using namespace xxx 
all the sub-namespace defined under xxx can be reached
using xxx
in fact, it's just a declaration.
only xxx itself can be reached, the sub-namespace should be used like xxx.sub-space 
such as
 using std::cout

The using directive allows the names in a namespace to be used without the namespace-name as an explicit qualifier. 

Of course, the complete, qualified name can still be used to improve readability.

using namespace [::] [ nested-name-specifier ] namespace-name

Remarks

Note the difference between the using directive and the using declaration : the using declaration allows an individual name to be used without qualification, the using directive allows all the names in a namespace to be used without qualification. This keyword is also used for type aliases.

If a local variable has the same name as a namespace variable, the namespace variable is hidden. It is an error to have a namespace variable with the same name as a global variable.

Note Note

Put your using directive at the beginning of the source code file to reduce the potential for unexpected behavior with IntelliSense.

The std namespace

The ANSI/ISO C++ standard requires you to explicitly declare the namespace in the standard library. 

For example, when using iostream, you must specify the namespace of cout in one of the following ways:

  • std::cout (explicitly)

  • using std::cout (using declaration)

  • using namespace std (using directive)


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值