定义一个学生结构体,数据成员包括学号,姓名,性别,生日,然后输出三个同学的数据
(1001011 王丽 F 1995/1012
1001012 李军 M 1995/5/24
1001013 赵斌 M 1994/2/25
)
C语言结构体的定义和初始化
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
加油小杜(接qt定制功能,单模块开发等) 2022-05-26 16:02关注#include <iostream> #include <stdio.h> #include <vector> using namespace std; struct Student { int id; char* name; char* sex; char* birthday; }; int main() { vector<Student> res; Student stu1; stu1.id=10001; stu1.name="王丽"; stu1.sex="F"; stu1.birthday="1995/10/12"; Student stu2; stu2.id=10002; stu2.name="李军"; stu2.sex="F"; stu2.birthday="1995/5/24"; Student stu3; stu3.id=10003; stu3.name="赵斌"; stu3.sex="F"; stu3.birthday="1995/2/25"; res.push_back(stu1); res.push_back(stu2); res.push_back(stu3); for(int i=0;i<res.size();++i) { printf("%d %s %s %s\n",res[i].id,res[i].name,res[i].sex,res[i].birthday); } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报