#includeusing namespace std; //老师的结构体 struct Student { string sname; int score; }; struct Teacher { string tname; struct Student sArray[5]; }; //赋值函数 void allocatespace(struct Teacher tArray[], int len) //给老师开始赋值 { string nameseed = "ABCDE"; for (int i = 0; i < len; i++) { tArray[i].tname = "Teacher_"; tArray[i].tname += nameseed[i]; //给学生赋值 for (int j = 0; j < 5; j++) { tArray[i].sArray[j].sname = "Student_"; tArray[i].sArray[j].sname += nameseed[j]; tArray[i].sArray[j].score = 60; } } } void printinfo(struct Teacher tArray[], int len) { for (int i = 0; i < len; i++ ) { cout << "老师名字:" << tArray[i].tname << endl; for (int j = 0; j < 5; j++) { cout << "t学生姓名:" << tArray[i].sArray[j].sname << "考试的分数: " << tArray[i].sArray[j].score << endl; } } } int main() { //创建3名老师的数组 struct Teacher tArray[3]; //通过函数与老师和学生赋值 int len = sizeof(tArray[3]) / sizeof(tArray[0]); allocatespace(tArray, len); //打印所有老师及学生的信息 printinfo(tArray, len); system("pause"); return 0; }
为什么只能显示第一部分



