首页 > 解决方案 > 0x7A47E727 中未处理的异常

问题描述

#include "pch.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{

    //system("cls");
    const int x = 30;
    const int y = 15;
    string tabella[y][x];
    char bordo = '#';
    for (int i = 0; i < x; i++)
        tabella[0][i] = bordo;
    for (int i = 0; i < y; i++)
        tabella[i][0] = bordo;
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            std::cout << tabella[i][j];
        }
        std::cout << "\n";
    }

}

我不知道为什么它给了我这个问题:

Eccezione non gestita in 0x7A47E727 (ucrtbased.dll) in Prova1.exe: 0xC0000005: violazione di accesso durante la lettura del percorso 0xCCCCCCCC。

这里是英文翻译:

Test1.exe 中 0x7A47E727 (ucrtbased.dll) 中的未处理异常:0xC0000005:读取路径 0xCCCCCCCC 时访问冲突。

问题似乎出在这一行: std::cout << tabella[i][j];

我不知道,但它是在我使用 xey 变量时开始的。我正在使用 Visual Studio 2017 顺便说一句。

标签: c++visual-studiounhandled-exception

解决方案


看看你的数组边界。你有ij错误的方式。

std::cout << tabella[i][j];

应该

std::cout << tabella[j][i];

或者,也许你一开始就x走错y了路。


推荐阅读