c++命名空間using

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.