The problem is in line 7 to 11. I don't recommend using 2D data structures, for example:
std::vector<std::vector<int>>, because there is quite an overhead.
Use a 1 dimensional data structure.
Determine the dimensions of the matrix and then put them in data members such as
int dim1 and
int dim2.
Then to access elements just use
m_arrBoard[i * dim2 + j] where
i is the row you want to be on,
dim2 is the total number of columns, and
j is the column you want to be on.
You can define a range checked function
index(int i, int j) that returns
i * dim2 + j and access elements like this
m_arrBoard[index(5, 5)]
Then to get data from a file to fill your
m_arrBoard you just load it regularly.
Example:
1 2 3 4 5
|
for(int i = 0; i < m_arrBoard.size(); ++i)
{
gamefile >> temp;
m_arrBoard[i] = temp;
}
|
or use the less verbose version
|
std::copy(std::istream_iterator<T>(gamefile), std::istream_iterator(), m_arrBoard.begin());
|
If you really insist on using a 2D data structure see the Boost Multidimensional Array Library.