MichaelBlog

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

导航

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 2022-04-16 09:48  Michael_chemic  阅读(235)  评论(0编辑  收藏  举报