创建一个结构体ST,成员有num(学号),name(姓名),score(成绩),birthday(出生日期),出生日期是一个名为date的结构体类型,初始化第1个人员的数据信息并赋予变量st1,再把此人信息赋给另一个变量st2,输出两个变量st1及st2的值。
时间: 2023-06-11 12:07:50 浏览: 86
```c++
#include <iostream>
#include <string>
using namespace std;
struct date {
int year;
int month;
int day;
};
struct ST {
int num;
string name;
float score;
date birthday;
};
int main() {
ST st1 = { 1001, "张三", 89.5, {2000, 5, 20} };
ST st2 = st1;
cout << "st1.num: " << st1.num << endl;
cout << "st1.name: " << st1.name << endl;
cout << "st1.score: " << st1.score << endl;
cout << "st1.birthday: " << st1.birthday.year << "-" << st1.birthday.month << "-" << st1.birthday.day << endl;
cout << "st2.num: " << st2.num << endl;
cout << "st2.name: " << st2.name << endl;
cout << "st2.score: " << st2.score << endl;
cout << "st2.birthday: " << st2.birthday.year << "-" << st2.birthday.month << "-" << st2.birthday.day << endl;
return 0;
}
```
输出结果:
```
st1.num: 1001
st1.name: 张三
st1.score: 89.5
st1.birthday: 2000-5-20
st2.num: 1001
st2.name: 张三
st2.score: 89.5
st2.birthday: 2000-5-20
```
阅读全文