12.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 = 10080;
	t.name = "老王";
	t.age = 30;
	t.stu.name = "小王";
	t.stu.age = 18;
	t.stu.score = 90;



	system("pause");
	return 0;
}
posted @ 2025-07-05 16:19  little小新  阅读(4)  评论(0)    收藏  举报