作用:将自定义的结构体放入到数组中方便维护
语法: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;
}
运行结果:
黑马程序员匠心之作|C++教程从0到1入门编程--练习-结构体数组

相关文章:

  • 2021-04-07
  • 2021-11-17
  • 2021-09-15
  • 2021-05-28
  • 2021-09-23
  • 2021-08-01
  • 2022-12-23
  • 2021-04-21
猜你喜欢
  • 2021-11-18
  • 2021-04-21
  • 2021-10-14
  • 2021-11-21
  • 2021-08-22
  • 2021-12-28
  • 2022-12-23
相关资源
相似解决方案