/*lzw.cpp*/ // C++源程序的扩展名是.cpp, 而C的源程序的扩展名是.C
#include <iostream> // 包含标准输入输出头文件 iostream
using namespace std;// 引入C++标准命名空间名 std
namespace one //定义空间名one, 有M和inf
{
const int M = 200;
int inf = 10;
} //后面不加分号
namespace two //定义空间名two,有x和inf,lzw
{
int x;
int inf = -100;
int lzw = 300;
} //后面不加分号
using namespace one; //using声明使用一个完整的名字空间 one
int main()
{
cout<<inf<<endl; //直接使用one中的所有成员
cout<<M<<endl;
cout<<"================="<<endl;
using two::x; //using声明仅使用two中的x;
x = -100; //直接访问,相当于two::x = -100
two::inf *=2; //使用名字空间名::局部内容名
cout<<two::inf<<endl;
cout<<x<<endl; //直接访问two的X
cout<<two::x<<endl;
cout<<two::lzw<<endl;
}
控制台结果: