gpt4 book ai didi

c++ - 0x7A47E727中未处理的异常

转载 作者:行者123 更新时间:2023-12-02 09:53:24 25 4
gpt4 key购买 nike

#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.



这里是英文翻译:

Unhandled exception in 0x7A47E727 (ucrtbased.dll) in Test1.exe: 0xC0000005: access violation while reading path 0xCCCCCCCC.



问题似乎在这一行: std::cout << tabella[i][j];
我不知道,但是当我使用x e y变量时它就开始了。
我正在使用Visual Studio 2017 btw。

最佳答案

您声明数组

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];

这将解决您的问题

关于c++ - 0x7A47E727中未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62408580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com