0
点赞
收藏
分享

微信扫一扫

结构体04:结构体嵌套结构体

Ad大成 2022-01-13 阅读 150
#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=10086;
	t.name="赵六";
	t.age=50;
	t.stu={"张三",18,100};
	
	cout<<t.id<<" "<<t.name<<" "<<t.age<<endl;
	cout<<t.stu.name<<" "<<t.stu.age<<" "<<t.stu.score<<endl;

	
}
举报

相关推荐

0 条评论