Puran Lai 2020-01-25 15:53 采纳率: 100%
浏览 3460
已采纳

Visual Studio 2019:RangeChecks 检测代码检测到超出范围的数组访问。

写了一个关于抽取学号的程序,如下:

    #include<iostream>
    #include<fstream>

    #include<cstring>
    #include<sstream>

    #include<iomanip>
    #include<algorithm>
    #include<cstdio>
    #include<ctime>
    #include<cstdlib>

    using namespace std;

    const string PASSWORD = "070714";
    int a, j, k, i, co = 0;
    int arr[55] = {};
    char m[200] = {};
    string in = "", n = "";

    void instructions() {
        cout << setw(60) << "使用说明";
        cout << "重启程序请输入“重启”,关闭程序请输入“退出”。" << endl;
        cout << "输入一个小于班级人数的数字,将输出一些随机数。" << endl;
        cout << "输入记事本模式以进入记事本模式,此时你可以输入文本,按Enter键确定。" << endl;
        cout << "输入打开记事本以查看记事本的内容。" << endl;
        cout << "\n\n\n还有彩蛋等你来试!\n\n\n";
        system("pause");
    }

    void show() {
        system("cls");
        system("color F1");
        cout << setw(50) << "抽奖程序" << setw(55) << "[Version 1.6]" << endl;
        cout << setw(60) << "重启程序请输入“重启”,关闭程序请输入“退    出”。" << endl;
        cout << "请输入人数:";
}

    int getrand() {
        srand(time(0)); //随机种子
        int a;
        a = rand() % 1000 + 1;
        while (a >= 1000)a -= 55;
        return a;
    }

    int main()
    {
        show();
        arr[55] = {};
        m[200] = {};
        a = i = j = k = co = 0;
        system("start osk");
        cin >> in;
        cout << endl;
        if (in == "退出") {
            exit(0);
        }
        else if (in == "重启") {
            system("start choujiang.exe");
            exit(1);
        }
        else if (in == "打开记事本") {
            ifstream in;
            in.open("NotePad.lpr");
            while (in >> m)in >> m;
            cout << m << endl;
            in.close();
            main();
        }
        else if (in == "记事本模式") {
            system("cls");
            ofstream out;
            system("color F4");
            cout << setw(70) << "记事本模式" << endl;
            out.open("记事本.lpr");
            cin >> n;
            out << n;
            out.close();
            cout << "成功!" << endl;
            system("pause");
            system("cls");
            main();
        }
        else if (in == PASSWORD) {
            cout << "管理员模式" << endl;
            system("pause");
            system("cls");
            show();
            cin >> in;
            system("cls");
            show();
            cout << endl << "中奖号码是" << in << "号" << endl;
            system("pause");
            main();
        }
        else {
            stringstream ss;
            ss << in;
            ss >> i;
        }
        if (i > 55) {
            cout << "人数超过55!!!" << endl;
            system("pause");
            system("cls");
            main();
        }
        while (j <= i - 1) {
            a = getrand();
            while (co <= j) {
                if (a == arr[j])
                    continue;
                else
                    arr[j + 1] = a;
                    j++;
            }
        }
        sort(arr, arr + i - 1);
        for (int z = 0; z < i; z++)cout << "中奖号码是" << arr[z] << "号" << endl;
        system("pause");
        main();
    }

报错图片:![图片说明](https://img-ask.csdn.net/upload/202001/25/1579938675_183844.png)
  • 写回答

3条回答 默认 最新

  • 玄黄问道 2020-01-25 16:50
    关注

    main中的

            arr[55] = {};
            m[200] = {};
    

    这两行去了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)