MichaelBlog

double i = Double.MAX_VALUE; while(i == i + 1){ System.out.print ("学无止境");};

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

C++: 结构体数组

C++: 结构体数组

将自定义结构体放入到数组中方便维护
语法结构: struct 结构体名 数组名[元素个数] = {{},{},{}…};

#include <iostream>
using namespace std;

struct Student {
    string name;
    int age;
    int score;
};

int main(){
    struct Student stuArray[3] = {
        { "Michael",18,100 },
         { "Mike",18,100 },
          { "Kity",18,100 },

    };

    stuArray[2].name = "Jack";
    stuArray[2].age = 19;
    stuArray[2].score = 99;

    for (int i = 0; i < 3; i++) {
        cout << "name" << stuArray[i].name 
                << "age" << stuArray[i].age
                <<"score"<<stuArray[i].score << endl;
    }
    system("pause");
    return 0;

}

posted on   Michael_chemic  阅读(247)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
点击右上角即可分享
微信分享提示