#include #include //结构体数组 //作用:将自定义的结构体放入到数组中方便维护 //语法:struct 结构体名 数组名[元素个数] = { {} , {} , ...{} } //1、定义结构体 #if(0) struct Student { //姓名 std::string name; //年龄 int age; //分数 int score; }; int main() { //2、创建一个结构体数组 struct Student stuArry[8] = { {"张三" , 18 , 100}, {"李四" , 28 , 99}, {"王五" , 38 , 66} }; //3、给结构体数组中的元素赋值 stuArry[2].name = "赵六"; stuArry[2].age = 80; stuArry[2].score = 60; //4、遍历结构体数组 for (int i = 0; i < 3; i++) { std::cout << "姓名:" << stuArry[i].name << "年龄:" << stuArry[i].age << "分数:" << stuArry[i].score << std::endl; } system("pause"); return 0; } #endif