#include<iostream>
using namespace std;
#include <string>
//结构体数组
//1.定义结构体
struct Student
{
string name;
int age;
int score;
};
int main(){
//2.创建结构体数组 (3并赋值)
struct Student stuArray[3]=
{
{"张三",18,100},
{"李四",20,99},
{"王五",17,67}
};
//3.后来赋值法--通过修改
stuArray[2].name="赵六";
stuArray[2].age=67;
stuArray[2].score=60;
//遍历结构体数组
for(int i=0;i<3;i++)
{
cout
<<"姓名: "<<stuArray[i].name
<<"年龄: "<<stuArray[i].age
<<"分数: "<<stuArray[i].score
<<endl;
}
system("pause");
return 0;
}
65结构体--结构体数组
最新推荐文章于 2024-07-25 23:22:43 发布