其他分享
首页 > 其他分享> > 066.结构体-结构图嵌套结构体

066.结构体-结构图嵌套结构体

作者:互联网

#include <iostream>
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 = 1000;
    t.age = 100;
    t.name = "老刘";
    t.stu.age = 50;
    t.stu.name = "小李";
    t.stu.score = 500;

    cout << "老师名字:" << t.name
        << "老师编号:" << t.id
        << "老师年龄:" << t.age
        << "老师辅导学生姓名:" << t.stu.name
        << "学生年龄:" << t.stu.age
        << "学生分数:" << t.stu.score << endl;

    system("pause");
    return 0;
}

 

标签:name,066,int,结构图,struct,嵌套,结构,age,stu
来源: https://www.cnblogs.com/ceovs/p/15227071.html