I need to create a program for class that inputs a file of a Maze into a two dimensional vector so the computer can return the vector to a class Maze. I'm currently working on the function that loads the Maze input into a vector. Every time I run the program it stops at the first conditional statement that is meant to check that each line is equal. It "couts" Error and then get abort error from MVS studio saying string subscript out of bounds. I've been searching online for possible errors but nothing has helped. Can someone please tell me what I am doing wrong?
Below is the code:
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
struct Location {
friend std::ostream &operator <<(std::ostream &os, const Location &location) {
os << "(" << location.x << ", " << location.y << ")";
return os;
}
//bool operator ==(const Location &rhs) const {return x == rhs.x && y == rhs.y;}
//bool operator !=(const Location &rhs) const {return !(*this == rhs);}
//operator bool() const {return x >= 0;}
Location(int x=-1, int y=-1) : x(x), y(y) {}
int x, y;
};
int main()
{
ifstream infile;
infile.open("Maze.txt");
vector<vector<bool> > mazeSpec; //row vector
vector<bool> column;
string top,currlin;
int row=0, col=0;
Location start, finish;
getline(infile, top);
int size= top.length();
for(int i=0; i<size; i++){
column.push_back(false);
}
cout<<top<<endl;
cout<<top.length();
//getline(infile,currlin);
//cout<<(currlin);
//cout<<currlin.length();
mazeSpec.push_back(column);
column.clear();
row++;
while (getline(infile,currlin)){
for(int i=0; i<size; i++){
if ((currlin.length()) != size){
//throw "Error! Line of Maze is too short!"; //check to see if rows of equal length
cout<<"Error!";}
//break;}
else if (currlin[i] == 'S'){
column.push_back(true);
start= (row, i);}
else if (currlin[i] == 'F'){
column.push_back(true);
finish= (row, i);}
else if (currlin[i] == ' ' || '+' || '|'){
column.push_back(false);
}
else if(currlin[i]== '*'){
column.push_back(true);}
}
row++;
currlin.empty();
mazeSpec.push_back(column);
column.clear();
}
infile.close();
int x;
cin>>x;
cin.ignore();
return 0;
}
Here is the Maze text:
+----------------------------------------+
|* F |
|* ***** ********* * |
|**** * * * * * |
| * * * * ******** |
| *** * * * * * |
| * * * * * * |
| ******* * * * |
| * **** * * * *****|
| * * * * * *|
| * ****** ******** *|
| * * *|
| S *******************|
+----------------------------------------+
Thanks!