char vector question

Hello, i just had question but did not understand the previous answers

I want to save the char[8][8] // fixed size 2 dimension array

to a vector

such as

vector<?????> temp;

is there anyway to approach this?
You mean you're trying to do a 2D vector?

vector<vector<char> > temp;

This should make the 2D vector array
I want to make vector for
char[8][8]

vector<char[8][8]....> temp

something like this

8.8 is fixed
When you do vector<vector<char> > temp; , it makes a 2d char vector. So temp[0][0] would be a slot, temp[n][n] would be another, etc...
When you do vector<vector<char> > temp; , it makes a 2d char vector. So temp[0][0] would be a slot, temp[n][n] would be another, etc...


vector<vector<char> > temp; makes an empty vector of empty vectors. Using temp[x][y] will try to access an element that doesn't exist unless the vectors are resized (or perhaps initialized correctly.)

vector<vector<char>> temp(8, vector<char>(8)) ;
creates a vector of 8 vectors of 8 char which may be used (almost) equivalently to:
char[8][8] temp ;

Alternately,
1
2
3
4
5
6
vector<vector<char>> temp ;
temp.resize(8) ;
for ( auto& element : temp )
    element.resize(8) ;

// now temp may be indexed appropriately. 

Last edited on
Topic archived. No new replies allowed.