using namespace std;
// 结构体数组 // 1.定义结构体 struct Student { // 成员列表 string name; int age; int score; };
int main() { // 2.创建结构体数组 struct Student stdArray[3] = { { “test”, 20, 100, }, { “test1”, 22, 100, }, { “test2”, 23, 100, }, }; // 3.给结构体中的元素赋值 stdArray[2].name = “test3”; stdArray[2].age = 50; stdArray[2].score = 10; // 4.遍历结构体数组 for (int i = 0; i < 3; i++) { cout << “name “ << stdArray[i].name << endl; cout << “age “ << stdArray[i].age << endl; cout << “score “ << stdArray[i].score << endl; } return 0; } ```
