There are much better ways to handle input files. Firstly, rather than using a vector<char>
, just use a std::string
, and rather than using a vector<vector<char> >
, just use a vector<string>
. I'm not sure I understand why row
is a member of the class if it is only being used to fill the board
. Anytime you need the last item in board you can just do board.back()
or *board.rbegin()
.
void Board::readInFile(void)
{
ifstream indata("Puzzle.txt", ios::in);
if(!ifstream.is_open())
return;
indata >> rows; //you don't really need to do this if you take
//the row count out of the file, but if you can't
//change the file, leave it in so as not to corrupt
//the loop that follows
string line;
while(getline(indata, line)){
board.push_back(line);
}
indata.close();
}
Really, you don't need to have the file store the rows
variable.
Your function would also be more reusable if readInFile took the filename as a parameter so it could open anything instead of only one specific filename.