func readMaze(fileName string) [][]int{ file, err := os.Open(fileName) if err != nil{ panic(err) } var row, col int fmt.Fscanf(file, "%d %d", &row, &col) maze := make([][]int, row) for i := range maze { maze[i] = make([]int, col) for j := range maze[i] { fmt.Fscanf(file, "%d", &maze[i][j]) } } return maze } func main() { maze := readMaze("src/maze/maze.in") for _, row := range maze{ for _, val := range row{ fmt.Printf("%d ",val) } fmt.Println() } //walk(maze, point{0, 0}, point{len(maze)-1, len(maze[0])-1}) }
//src/maze/maze.in文件内容
6 5 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 0 0
但是读取之后变成了
0 0 1 0 0
0 0 0 0 0
1 0 0 0 1
0 1 0 0 1
1 1 0 0 0
0 1 0 0 1
不知道什么原因,win开发环境,IDE是golang,请大家指点
有疑问加站长微信联系(非本文作者)