结构体数组

 1 #include <iostream>
 2 using namespace std;
 3 struct Student
 4 {
 5     string name;
 6     int age;
 7     int score;
 8 };
 9 int main() {
10     struct Student stuArray[3] =
11         {
12                 {"张三",18,100},
13                 {"李四",28,99},
14                 {"王五",38,66}
15         };
16     stuArray[2].name="赵六";
17     stuArray[2].age=80;
18     stuArray[2].score=60;
19     for(int i=0;i<3;i++)
20     {
21         cout<<"姓名:"<<stuArray[i].name<<" "
22         <<"年龄:"<<stuArray[i].age<<" "
23         <<"分数"<<stuArray[i].score
24         <<endl;
25     }
26     return 0;
27 }

 

posted @ 2022-03-13 17:38  赵凤武  阅读(52)  评论(0)    收藏  举报