I'm new to C++ and this is my first attempt at a 3D vector. I'm trying to take an input file like this:
xxooo##xx
xoxxxoxoo
xxx#oxoo#
oxxxoxoox
xxoooo#xx
xxxo#o###
xxo#o#xxo
x##oxxoox
xxx##oxoo
xoxx#xooo
And turn it into a 3D char vector where each line is a 3x3 box with the first three characters being the first row, the next three the 2nd row, and the last three the 3rd row. For example the first row of the input should turn into this:
x x o
o o #
# x x
This is my attempt at a solution, but I feel that I've probably made several mistakes:
vector<vector<vector<char> > > makeBoard(vector<string> iflines)
{// Function to fill game boards from input strings
vector<vector<vector<char> > > charboard;
for (int i = 0; i != iflines.size(); i++)
{
for (int j = 0; j < 9; j++)
{
charboard[i][j/3][j%3] = iflines[i][j];
}
}
return charboard;
}
Would someone please help me out here?
Aucun commentaire:
Enregistrer un commentaire