结构体嵌套结构体
#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;
}
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号