C++ 命名空间 实战(一)
生活随笔
收集整理的這篇文章主要介紹了
C++ 命名空间 实战(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <iostream>
using namespace std;// 第一個命名空間
namespace first_space {void func() {cout << "Inside first_space" << endl;}
}
// 第二個命名空間
namespace second_space {void func() {cout << "Inside second_space" << endl;}
}
int main()
{// 調用第一個命名空間中的函數first_space::func();// 調用第二個命名空間中的函數second_space::func();return 0;
}
Inside first_space
Inside second_space
#include <iostream>
using namespace std;// 第一個命名空間
namespace first_space {void func() {cout << "Inside first_space" << endl;}
}
// 第二個命名空間
namespace second_space {void func() {cout << "Inside second_space" << endl;}
}
using namespace first_space;
int main()
{// 調用第一個命名空間中的函數func();return 0;
}
Inside first_space
#include <iostream>
using std::cout;int main ()
{cout << "std::endl is used with std!" << std::endl;return 0;
}
std::endl is used with std!
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的C++ 命名空间 实战(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++ 命名空间 using names
- 下一篇: s3c2440移植MQTT