例题7.1 声明学生结构体Student
定义两个结构体变量student1和student2
成员包括学号 姓名 性别 出生日期 成绩
学生1初始化
把学生1复制给学生2
输出学生2
#include <iostream> #include <string.h> using namespace std; struct Date{ int month; int day; int year; }; struct Student{ int num; string name; char sex; int age; Date birthday; float score; string addr; }student1={10001,"zhangsan",'m',23,12,12,2017,100,"北京市昌平区马池口吉利大学"},student2; int main(){ student2=student1; cout<<student2.num<<endl; cout<<student2.name<<endl; cout<<student2.sex<<endl; cout<<student2.age<<endl; cout<<student2.birthday.year<<'/'<<student2.birthday.month<<'/'<<student2.birthday.day<<endl; cout<<student2.score<<endl; cout<<student2.addr<<endl; return 0; }
本文通过一个具体的C++程序示例介绍了如何定义并初始化结构体,并演示了将一个结构体变量的内容复制到另一个结构体变量的过程。示例中包含了学生信息的结构体定义、初始化及复制操作。
5万+

被折叠的 条评论
为什么被折叠?



