职业养老选手 2022-05-26 15:42 采纳率: 100%
浏览 36
已结题

C语言结构体的定义和初始化

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

  • 写回答

1条回答 默认 最新

  • 加油吧,小杜 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;
    }
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月11日
  • 已采纳回答 6月3日
  • 创建了问题 5月26日

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因