我正在将文件读入数组。它正在读取每个字符,问题在于它还读取了文本文件中的换行符。
这是一个数独板,这是我在字符中读取的代码:
bool loadBoard(Square board[BOARD_SIZE][BOARD_SIZE])
{
ifstream ins;
if(openFile(ins)){
char c;
while(!ins.eof()){
for (int index1 = 0; index1 < BOARD_SIZE; index1++)
for (int index2 = 0; index2 < BOARD_SIZE; index2++){
c=ins.get();
if(isdigit(c)){
board[index1][index2].number=(int)(c-'0');
board[index1][index2].permanent=true;
}
}
}
return true;
}
return false;
}
就像我说的,它读取文件,显示在屏幕上,只是在遇到 \n 时顺序不正确