1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 | #include<iostream>
using namespace std;
#include<string>
/*1.定义一个结构体*/
struct student
{
string name;
int age;
int score;
};
/*1.结构体嵌套*/
struct teacher
{
string name;
int id;
int age;
struct student stu[30];
};
int main()
{
teacher t;
t.name = "老王 ";
t.id = 1111 ;
t.age = 35 ;
t.stu[0].name = "小叶 ";
t.stu[0].age = 22 ;
t.stu[0].score = 88 ;
cout << "老师姓名:" << t.name << " 老师编号:" << t.id << " 老师年龄:"
<< t.age << '\n'<<"学生姓名:" << t.stu[0].name << " 学生年龄:" << t.stu[0].age << " 学生成绩" << t.stu[0].score << endl;
return 0;
}
|