Please tell me how to do it right. I need an array of Char Field [20] [20] filled with characters from a file.
I did the following function:
void Spiel::readFile(std::string fileName) { std::ifstream file(fileName.c_str()); if (!file.is_open()) { std::cerr << "Error opening file: " << fileName << std::endl; exit(1); } std::string line; int a = 0; while (true) { if (a == 21) break; std::getline(file, line); for (int i = 0; i < 20; i ++) { if (line[i] == std::string::npos) { Field[a][i] = '#'; } else { Field[a][i] = line[i]; } } a++; // weiter machen if, wenn Field [i][j] == "B", bx = i, by = j } std::cerr << "Done" << std::endl; } int main(int argc, char** argv) { Spiel spiel; spiel.readFile(std::string(argv[1])); }; According to gdb print Field or print line, it gives incomprehensible numbers and signs, but not like letters that are in the readable file. I can not understand what is wrong
while(true) { if(a==21) ...Reading this brain code is difficult to grasp the point. - PinkTux