作用: 结构体中的成员可以是另一个结构体
例如 每个老师辅导一个学员 一个老师的结构体中,记录一个学生的结构体
#include<iosteam>
using namespace std;
#include<string>
struct student {
string name;
int age;
int score;
};
struct teacher{
int id;
stirng name;
int age;
struct student stu; //辅导的学生
};
int main(){
//结构体嵌套结构体
teacher t;
t.id = 100000;
t.name = "老王";
t.age = 50;
t.stu.name = "小王";
t.stu.age = 20;
t.stu.score = 100;
cout << "老师的编号"<< t.id<<"老师的年龄"<<t.age<<"老师的名字"<<t.name<<"老师带的学生名字"<<t.stu.name<<endl;
}