vectors increase their size automatically when you add elements to it. So in fact a vector with 1x4 is equivalent to a vector 4 and can be enlarged to a vector of max_size(). Vectors have no fixed number of elements. If you are not going to enlarge your vector you can, for example, for a vector 3x4 to write
std::vector<std::vector<int>> v( 3, 4 );
and then to set values to its elements as for example
I defined my vector like in the following link (Line 5) and tried to add a row like you said (Line 6), but i still get error... what am i doing wrong? I just wanna add a row, column size is fixed. For example:
First: (defining the 2D vector)
Why two vectors are defined with the same name? I understand the first statement if to rewrite it simply
std::vector<std::vector<int>> tabu( 1, m );
But I do not understand what you meant when you are defining the seconst vector with the same name as the first?! If you want that the vactor 1 x M will be a vector 4 x m then you should push_back three additional elements to it.
For example
1 2 3 4 5 6
std::vector<std::vector<int>> tabu( 1, m );
for ( int i = 0; i < 3; i++ )
{
tabu.push_back( std::vector<int>( m ) );
}
#include <iostream>
usingnamespace std;
int **a; //Global Variable
int main()
{
n=5;
a = newint*[n];
for ( int i = 0 ; i < n ; i++ ) a[i] = newint[n] ;
}
is there any realloc() method to increase the row size +1? (column size is fixed again)
I mean if the row size is 5 then i wanna make it 6.
I use
You should select either you use std::vector or you use dynamically allocated memory in heap.
I think that there is no any sense to answer your question because you do not know what you wont.