请问一下我这个C++程序问题出现在哪里

请问一下我这个C++程序问题出现在哪里,第1张

#include 
using 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;

}

为什么只能显示第一部分

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/793732.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存