定义一个学生结构体,数据成员包括学号,姓名,性别,生日,然后输出三个同学的数据
(1001011 王丽 F 1995/1012
1001012 李军 M 1995/5/24
1001013 赵斌 M 1994/2/25
)
#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;
}