在C++中,结构体数组的定义和使用可以通过以下步骤来实现:
struct Student { string name; int age; float score; }; Student students[3]; students[0].name = "Alice"; students[0].age = 20; students[0].score = 85.5; students[1].name = "Bob"; students[1].age = 21; students[1].score = 90.0; students[2].name = "Charlie"; students[2].age = 19; students[2].score = 78.5; for (int i = 0; i < 3; i++) { cout << "Name: " << students[i].name << endl; cout << "Age: " << students[i].age << endl; cout << "Score: " << students[i].score << endl; } 使用这些步骤,你就可以定义和使用结构体数组。注意,在使用结构体数组之前,需要包含相应的头文件(例如,iostream)和使用命名空间(例如,using namespace std)。