我正在编写代码以读取代表“迷宫”的文件中的 7x15 文本块。
#include <iostream>
#include <fstream>
#include <string>
#include "board.h"
int main()
{
char charBoard[7][15]; //the array we will use to scan the maze and modify it
ifstream loadMaze("maze"); //the fstream we will use to take in a maze
char temp; //our temperary holder of each char we read in
for(int i = 0;i < 7; i++)
{
for(int j = 0; j < 15; j++)
{
temp= loadMaze.get();
charBoard[i][j] = temp;
cout << charBoard[i][j]; //testing
}
cout << endl;
}
return 0;
}
这是我的原始草稿,但由于它不断返回,所以这不起作用?对于它读取的每个字符。这是我正在测试的迷宫:
############# # ############# # ######### #### #!# ############
编辑: cout 正在打印:
############# # ############ # # ######### #### #! # #########
我不是在逃避 \n 的吗?
我已经编码了几个小时,所以我认为这是一个我没有发现的简单错误,这让我现在绊倒了。谢谢!