在C++中,結(jié)構(gòu)體數(shù)組的定義和使用可以通過以下步驟來實現(xiàn):
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;
}
使用這些步驟,你就可以定義和使用結(jié)構(gòu)體數(shù)組。注意,在使用結(jié)構(gòu)體數(shù)組之前,需要包含相應的頭文件(例如,iostream)和使用命名空間(例如,using namespace std)。