標籤:ios 編譯 函數 自訂 改變 變數 空間 hello code
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 }
c++命名空間using