结构体数组
- struct 结构名 变量名[数组大小]
#include <iostream>
#include <Windows.h>
using namespace std;
struct student {
char name[32];
int age;
};
int main(void) {
//定义了一个结构体数组, 包含2个学生
struct student a[2];
//第一个学生赋值
a[0] = { "小黑", 18 };
//第二个学生赋值
strcpy_s(a[1].name, 5, "小白");
a[1].age = 19;
//数组方式访问
cout << "学生1姓名: " << a[0].name << "\t年龄: " << a[0].age << endl;
cout << "学生2姓名: " << a[1].name << "\t年龄: " << a[1].age << endl;
system("pause");
return 0;
}