Я пытаюсь построить и распечатать массив 2d, но его показ будет пустым, когда я попытаюсь распечатать его, чтобы произошла ошибка где-то, но я не могу найти его. Может кто-нибудь помочь? Я добавил код для инициализации массива.C++ print/build 2d array
#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);
//print function
void printMaze();
// You can add more functions if you like
private:
// Private data and methods
int size, rowX, colY;
char matrix[30][30];
};
#endif /* MAZE_HPP_ */
void Maze::readFromFile(std::ifstream &f) {
std::string line;
int i, j;
getline(f, line);
for(i = 0; i < size; i++) {
getline(f, line);
for(j = 0; j < size; j++) {
matrix[j][i] = line[j];
}
}
f.close();
}
void Maze::printMaze() {
int i, j;
for(i = 0; i < size; i++) {
for(j = 0; j < size; j++) {
std::cout << matrix[i][j] << "";
std::cout << "line";
}
std::cout << std::endl;
}
}
Как его запустить? Что такое 'размер'? Он инициализирован и как? – sashkello
добавил файл заголовка, где его инициализировал – user41829
. Я не вижу размер, инициализированный в любом месте. Его значение не определено. – sashkello