C++ 我想读一个“我想读一读”;生命的游戏。将txt文件转换为二维数组c++;

C++ 我想读一个“我想读一读”;生命的游戏。将txt文件转换为二维数组c++;,c++,conways-game-of-life,C++,Conways Game Of Life,这就是我到目前为止所拥有的: bool read_universe_file (ifstream& inputfile, Cell universe [Rows][Columns]) { int i,j = 0; string filename; cout << "Enter the name of the file yo want to use: "; cin >> filename; ifstream m

这就是我到目前为止所拥有的:

bool read_universe_file (ifstream& inputfile, Cell universe [Rows][Columns])   
{
     int i,j = 0;
     string filename;
     cout << "Enter the name of the file yo want to use: ";
     cin >> filename;
     ifstream myfile(filename.c_str());

     while(infile)
     {
        //char a = infile.get();
        char a;
        infile >> a;
        universe[i][j] = (Cell)a;
        i++;
        if(a == '\n')
        {
            j++;
            i = 0;
        }
    }
}
bool read\u universe\u文件(ifstream&inputfile,单元格universe[行][列])
{
int i,j=0;
字符串文件名;
cout>文件名;
ifstream myfile(filename.c_str());
while(填充)
{
//char a=infle.get();
字符a;
填充>>a;
宇宙[i][j]=(单元)a;
i++;
如果(a=='\n')
{
j++;
i=0;
}
}
}

它确实运行,但不起作用。

比如说cin>>noskipws;在您的功能开始时。这将避免格式化输入跳过空白。我想这是你打算采取的行动方式


关于

请定义“它不起作用”。“它不起作用”是因为……?您错过了针对您的数据格式(数组行x列)的文件输入验证-而且您不应该使用“\n”作为前进到下一行的条件(它是一个空白字符,从未在格式化输入中显示)我不知道为什么它不起作用;它开始运行,(我想)在一个循环后,它说寻找解决方案,编译器停止