c++程序—結構體數組


#include<iostream>
using namespace std;
#include<string>
//結構體數組

struct student 
{
    string name;
    int age;
    float score;
};

int main()
{
    struct student studentArr[3] =
    {
        {"張三",18,97.5},
        {"李四",19,60},
        {"王五",17,78},
    };

    studentArr[1].score = 85.5;

    for (int i = 0; i < 3; i++) 
    {
        cout << "姓名: " << studentArr[i].name <<"  "
             << "年齡: " << studentArr[i].age <<"  "
             << "分數: " << studentArr[i].score<<"  " << endl;
    }
    system("pause");
    return 0;

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM