C++ 从文件打印出二维数组

C++ 从文件打印出二维数组,c++,C++,如何将此文本文件以2D数组的形式打印到控制台窗口 我写了这段代码,但它似乎忽略了空格作为字符 ifstream mazefile("maze.txt"); char maz[21][31] = {}; int i, j; for (i = 0; i < 21; i++) { for (j = 0; j < 31; j++) { mazefile >> maz[i][j]; cout << maz[i][j

如何将此文本文件以2D数组的形式打印到控制台窗口

我写了这段代码,但它似乎忽略了空格作为字符

ifstream mazefile("maze.txt");

char maz[21][31] = {};

int i, j;

for (i = 0; i < 21; i++)
{
    for (j = 0; j < 31; j++)
    {
        mazefile >> maz[i][j];
        cout << maz[i][j];
    }
    cout << endl;
}
ifstream mazefile(“maze.txt”);
char-maz[21][31]={};
int i,j;
对于(i=0;i<21;i++)
{
对于(j=0;j<31;j++)
{
mazefile>>maz[i][j];

默认情况下,
std::istream::operator
mazfile.get(maz[i][j]);
mazfile.get();  // Trailing newline

mazfile.get(maz[i], 30);
mazfile.get();  // Trailing newline

mazfile.get(maz[i], 30, '\n');  // With newline as delimiter
mazfile.get();  // Trailing newline

mazfile.getline(maz[i]);
mazfile >> noskipws >> maz[i][j];