навигация лабиринта массива c ++ 2d

0

Я новичок в c++ и задаюсь вопросом, делаю ли я это наилучшим образом. Мне нужно прочитать строку из текстового файла и построить из него массив, а затем переместить его. Дайте мне знать, если я что-то делаю неправильно. Могу ли я получить доступ к матрице так, как я?

заголовок:

#ifndef MAZE_HPP_
#define MAZE_HPP_

#include <fstream>
#include <vector>
#include <string>

class Maze
{
public:
    Maze(int size);
    ~Maze() {}

    enum Direction { DOWN, RIGHT, UP, LEFT };

    // Implement the following functions:

    // read maze from file, find starting location
    void readFromFile(std::ifstream &f);

    // make a single step advancing toward the exit
    void step();

    // return true if the maze exit has been reached, false otherwise
    bool atExit();

    // set row and col to current position of 'x'
    void getCurrentPosition(int &row, int &col);

    // You can add more functions if you like
private:
    // Private data and methods
    int size;
    static string matrix[30][30];
};


#endif /* MAZE_HPP_ */

c++ файл:

#include <iostream>
#include "maze.hpp"
#include "utils.hpp"
#include <vector>
#include <string>

Maze::Maze(int size) {
    size = size;
}

Maze::void readFromeFile(std::ifstream &f) {
    std::string line;
    int i, j;
    while(std::getline(f, line)) {
        for(i = 0; i < line.length(); i++) {
            for(j = 0; j < line.length(); j++) {
                matrix[i][j] = line.at(j);
            }
        }
    }
}

Maze::void step() {

}

Maze::bool atExit() {

}

Maze::void getCurrentPosition(int &row, int &col) {

}
  • 0
    Это компилируется?
  • 2
    Когда вы использовали отладчик, какие проблемы вы обнаружили?
Показать ещё 1 комментарий
Теги:
arrays
multidimensional-array

1 ответ

1
Лучший ответ
Maze::void readFromeFile {}
Maze::void step() {}
Maze::bool atExit() {}
Maze::void getCurrentPosition(int &row, int &col) {}

они должны быть

void Maze::readFromeFile{}
void Maze::step() {}
bool Maze::atExit(){}
void Maze::getCurrentPosition(int &row, int &col){}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню