1 #include <iostream> 2 using namespace std; 3 4 namespace spaceA{ 5 int g_a = 10; 6 namespace spaceB{ 7 //定义一个结构体 8 struct teacher{ 9 int id; 10 char name[64]; 11 }; 12 //结构体定义结束 13 } 14 15 } 16 using namespace spaceA; 17 int main(){ 18 cout << "hello word!" << endl; 19 cout << g_a << endl; 20 //引用命名空间的结构体 21 using spaceA::spaceB::teacher; 22 //实例化结构体,取名叫t1 23 struct teacher t1; 24 //使用结构体成员ID,并为其赋值100 25 t1.id = 100; 26 return 0; 27 28 }