0x7A47E727中未处理的异常。

问题描述 投票:-1回答:1
#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)中的Unhandled异常:0xC0000005:在读取路径0xCCCCCCCC时访问违规。

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

我不知道,但这是在我使用x e y变量时开始的。顺便说一下,我使用的是Visual Studio 2017。

c++ c visual-studio unhandled-exception
1个回答
1
投票

你声明数组

const int x = 30;
const int y = 15;
string tabella[y][x];

但这里你用错了指数。

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

因为 i 从0到29的计数和 j 数值从0到14。

所以你必须使用。

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

这样就能解决你的问题


2
投票

看看你的数组边界。你有 ij 错了

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

应是

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

或者你有 xy 一开始就错了方向。

© www.soinside.com 2019 - 2024. All rights reserved.