Hello All,
I seem to be having a relatively small problem with a Maze program I'm working on. Basically, I read a txt file containing a maze into a 12 x 12 2D array, but the problem is when I try to display it, none of the white spaces that are in the maze show up. I know it has something to do with the getline() function, but I have no clue as to where to put it.
Here is what an example of a txt file used contains:
~~~~~~~~~~~~
~ = ? *~
~ = ^ ? ^ *~
~ = ^ ? ^ *~
~ ^ ^ =~
~***^~~~^ =~
~ =~
~ ===???^^^~
~ ^~
~~ ~~ ^~
~ ~ $~
~~~~~~~~~~~~
Here is my code so far:
#include "Maze.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
Maze::Maze()
{
mazeStore[12][12] = ' ';
}
int Maze::inputMaze()
{
string fileName;
char ch;
cout << "Enter the file name: ";
cin >> fileName;
ifstream inFile;
inFile.open(fileName.c_str());
if (!inFile)
{
cout << "File could not be opened." << endl;
exit(1);
}
else
{
while (!inFile.eof())
{
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 12; j++)
{
inFile >> mazeStore[i][j];
}
}
}
inFile.close();
}
}
void Maze::outputMaze()
{
cout << "MAZE:\n";
cout << " 111\n";
cout << " 123456789012\n";
for(int a = 0; a < 12; a++)
{
for(int b = 0; b < 12; b++)
{
cout << mazeStore[a][b];
}
cout << endl;
}
return;
}
Thanks in advance for any help given!