#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";
}
}
I don't why it gaves me this problem:
Eccezione non gestita in 0x7A47E727 (ucrtbased.dll) in Prova1.exe: 0xC0000005: violazione di accesso durante la lettura del percorso 0xCCCCCCCC.
Here it is translated in English:
Unhandled exception in 0x7A47E727 (ucrtbased.dll) in Test1.exe: 0xC0000005: access violation while reading path 0xCCCCCCCC.
The problem seems to be in this line:
std::cout << tabella[i][j];
I don't know but it started when I used the x e y variables. I'm using Visual Studio 2017 btw.
You declare the array
const int x = 30;
const int y = 15;
string tabella[y][x];
but here you use the indices wrong:
std::cout << tabella[i][j];
because i
counts from 0 to 29 and j
counts from 0 to 14.
So you have to use:
std::cout << tabella[j][i];
This will solve your problem