黑马程序员匠心之作|C++教程从0到1入门编程--练习-结构体数组
发表时间:2020-10-19
发布人:葵宇科技
浏览次数:62
作用:将自定义的结构体放入到数组中方便维护
语法:struct 结构体名 数组名[元素个数] = { {} , {} , … {} }
#include
#include
using namespace std;
struct Student
{
string name;
int age;
int score;
};
int main()
{
struct Student arr[3]=
{
{“张美丽”,18,100},
{“曾美丽”,18,100},
{“彭美丽”,18,100}
};
for (int i = 0; i < 3; i++)
{
cout << “姓名” << arr[i].name << “年龄” << arr[i].age<<“分数” << arr[i].score<<endl;
}
system(“pause”);
return 0;
}
运行结果: