c++命名空间using

 1 #include<iostream>
 2 
 3 namespace run1
 4 {
 5     int x = 10;
 6 }
 7 namespace run2
 8 {
 9     int x = 10;
10 
11     void show()
12     {
13         std::cout << x << std::endl;
14     }
15 }
16 void run()
17 {
18 
19     using namespace std;//等同局部变量
20     using namespace run1;
21     using namespace run2;//发生
22     //cout << "hello world"<<x;
23 }
24 
25 void main()
26 {
27     std::cout << "hello doubo";
28     using  run2::x;
29     using  run2::show;//单独引用命名空间变量或者函数
30     std::cout << x << std::endl;
31     show();
32     std::cin.get();
33 
34 }
 1 #include<iostream>
 2 
 3 //using,可以省略std,
 4 //制定命名空间,
 5 //原则禁止using namespace std;//明确空间
 6 
 7 namespace  stdrun
 8 {
 9     int num = 101;
10     void show()
11     {
12         std::cout << num << std::endl;
13     }
14 }
15 namespace bobo = stdrun;//给自定义的别名
16 
17 
18 namespace doubo = std;//给标准别名,不推荐
19 //CPP编译器设置,禁止改变标准
20 
21 
22 void main()
23 {
24     bobo::show();
25     doubo::cout << "hello";
26     doubo::cin.get();
27 }

 

转载于:https://www.cnblogs.com/lanjianhappy/p/6082092.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值