作用:将自定义的结构体放到数组中方便维护
语法:struct 结构体名 数组名 {元素个数}={{},{},{}......}
#include <iostream>
#include<cstring>
using namespace std;
struct student
{
string name;
int age;
int score;
};
int main()
{
struct student arr[3]=
{
{"张三",18,100},
{"李四",19,100},
{"王五",20,90}
};
//给结构体数组中的元素赋值
arr[2].name="赵六";
arr[2].age=80;
for(int i=0;i<3;i++)
{
cout<<"姓名"<<arr[i].name<<"年龄"<<arr[i].age<<"成绩"<<arr[i].score<<endl;
}
return 0;
}