I am attempting to create a maze that is imported from a file and then placed into a vector that holds a vector of bools but I am not good yet with vectors. My problem is that I have taken the info from the file but I am unsure of how to then process it into the 2d vector. In the maze any coordinate that has a "+" is a path while anything else (blank space, etc) is a wall. The start and finish locations are Location objects, but i have not coded that yet. Any help would be appreciated, thanks
vector<vector<bool> > mazeSpec;
string buffer; //holds lines while they are read in
int length; //holds length of each line/# of columns
bool path; //test if path or not
Location start, finish;
vector<vector<bool> > mazeSpec;
ifstream mazeFile("maze.txt");
if (!mazeFile)
cout << "Unable to open file";
getline(mazeFile, buffer); // read in first line
cout << buffer << endl; //output first line
length = buffer.length(); //length now set so can be compared
while (!mazeFile.eof()) { // read in maze til eof
getline(mazeFile, buffer);
if (buffer == "*") //set path to true or false
path = true;
else
path = false;
cout << buffer << endl;
}
vector <vector <bool> > mazeSpec;
ifstream mazeFile( ... );
if (!mazeFile)
{
... // fooey!
}
else
{
string buffer;
while (getline( mazeFile, buffer )) // for each line
{
vector <bool> row;
for (auto c : buffer) // for each character
{
row.push_back( c == '*' );
}
mazeSpec.push_back( row );
// If you wanted to make sure that the rows are all the
// same length (as row 0), you can do it here:
if (mazeSpec.back().size() != mazeSpec.front().size())
{
... // fooey!
}
}
mazeFile.close();
}
that does help, however I'm not familiar with "auto" since i don't really know the new stuff from c++ 11. what does that mean/how would I implement it not using that?