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 }