我想读取一个由30x100整数组成的文本文件:https://pastebin.com/wemNrdMZ
由于某些原因,如果我将文件读入char数据类型,它会完美显示。但是当我将数据类型更改为int时,显示变得完全混乱:https://imgur.com/k0k11lH
这是我的代码:
int const row = 30;
int const colum = 100;
int map[row][colum];
fstream inFile;
inFile.open("map.txt"); //Located at the same location as .cpp file
if (inFile.is_open())
{
for (int i = 0; i < row; i++)
for (int j = 0; j < colum; j++)
{
inFile >> map[i][j];
}
inFile.close();
}
else
{
cout << "file not found" << endl;
}
for (int i = 0; i < row; i++)
{
for (int j = 0; j < colum; j++)
{
cout << map[i][j];
}
cout << endl;
}
}
如果我从int更改为char:https://imgur.com/GsXnPUI
,则读取成功