Consider a two-dimensional vector with integers, but initially only with one element:
std::vector< std::vector <int> > vec( 1, std::vector<int>( 1, 0 ) );
Now I want to make the vector in both dimensions larger, so that the vector results always in a m x m matrix.
Will the following two commands do that:
vec.push_back( std::vector<int> );
vec[0].push_back( 0 );
or will just the first row and respectively the first column increase by an element?
Only the first row will enlarge. The fact the vectors are all grouped together doesn't make them enlarge together.
If you are creating a vector of vectors, you will need to increase every row if you want the width of every row to increase....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With