sifarmer 2021-09-30 16:21 采纳率: 100%
浏览 82
已结题

代码功能为:assign函数通过结构体指针为主函数中结构体赋值。 出现错误提示:引发了异常: 读取访问权限冲突。 **_Pnext** 是 0xFF

img

#include <iostream>
#include <string>
using namespace std;

//学生结构体
struct student {
    string name;
    int    score{};
};

//老师结构体
struct teacher {
    string name;
    student stu_arr[5];
};

//assignment function
void assign(teacher* p, string tch_name[3], string stu_name[3][5], int scores[3][5])
{
    for (int i = 0; i < 3; i++)
    {
        p->name = tch_name[i];
        for (int j = 0; j < 5; j++)
        {
            p->stu_arr[j].name = stu_name[i][j];
            p->stu_arr[j].score = scores[i][j];
        }
    }
    return;
}

int main()
{
    teacher tch_arr[3];
    //teacher* p[3];
    //p[0] = &tch_arr[0];
    //p[1] = &tch_arr[1];
    //p[2] = &tch_arr[2];
    //assignment
    string tch_name[3] = { "老李","老王","老张" };
    string stu_name[3][5] = 
    {
        { "1张三","1李四","1王五","1赵六","1周七" },
        { "2张三","2李四","2王五","2赵六","2周七" },
        { "3张三","3李四","3王五","3赵六","3周七" }
    };
    int    scores[3][5] =
    {
        { 50, 60, 70, 80, 90 },
        { 78, 97, 55, 65, 85 },
        { 85, 62, 43, 66, 90 }
    };
    assign(tch_arr, tch_name, stu_name, scores);

    for (int i = 0; i < 3; i++)
    {
        cout << tch_arr[i].name << "老师的学生成绩如下:" << endl;
        for (int j = 0; j < 5; j++)
        {
            cout << tch_arr[i].stu_arr[j].name << ": " << tch_arr[i].stu_arr[j].score << "\t";
        }
        cout << endl;
    }
    system("pause");
    return 0;
}

// MEMBER FUNCTIONS FOR _Container_base12
_CONSTEXPR20_CONTAINER void _Container_base12::_Orphan_all_unlocked() noexcept {
    for (auto& _Pnext = _Myproxy->_Myfirstiter; _Pnext; _Pnext = _Pnext->_Mynextiter) { // TRANSITION, VSO-1269037
        _Pnext->_Myproxy = nullptr;
    }
    _Myproxy->_Myfirstiter = nullptr;
}
  • 写回答

1条回答 默认 最新

  • 关注

    用malloc申请出一片空间赋值给tch_arr,大小为结构体大小乘结构体个数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月12日
  • 已采纳回答 10月4日
  • 创建了问题 9月30日

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流