6.4重学C++之【结构体嵌套结构体】

#include<iostream>
#include<string>
using namespace std;


/*
    结构体嵌套结构体
*/


struct student{
    string name;
    int age;
    int score;
};


struct teacher{
    int id;
    string name;
    int age;
    struct student stu;
};


int main(){
    teacher t;
    t.id = 10000;
    t.name = "老王";
    t.age = 50;
    t.stu.name = "小李";
    t.stu.age = 18;
    t.stu.score = 99;

    // 场景:老师一对一辅导
    cout << "老师姓名:" << t.name << ",老师编号:"  << t.id << ",老师年龄:" << t.age << endl;
    cout << "学生姓名:" << t.stu.name << ",学生年龄:"  << t.stu.age << ",学生成绩:" << t.stu.score << endl;

    return 0;
}

posted @ 2021-03-11 12:04  yub4by  阅读(50)  评论(0编辑  收藏  举报