结构体嵌套结构体

#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=100;
t.name="老王";
t.age=50;
t.stu.name="小王";
t.stu.age=20;
t.stu.score=60;
cout<<"老师编号:"<<t.id<<endl;
cout<<"老师姓名:"<<t.name<<endl;
cout<<"老师年龄:"<<t.age<<endl;
cout<<"学生姓名:"<<t.stu.name<<endl;
cout<<"学生年龄:"<<t.stu.age<<endl;
cout<<"学生分数:"<<t.stu.score<<endl;


return 0;
}

posted @ 2022-03-13 17:56  赵凤武  阅读(38)  评论(0)    收藏  举报