So, im trying to create a 3 dimensional 5x3x2 vector, using the vector lib and saving the number 4 in every node.
Thats what im trying:
vector<vector<vector<int> > > vec (5,vector <int>(3,vector <int>(2,4)));
for a bi dimensional 5x8 saving the int 6 in every node, this works:
vector<vector<int> > vec (5,vector <int>(8,6));
You almost got it right -- the second nested vector
should be vector<vector<int> >
, not just a vector<int>
:
vector<vector<vector<int> > > vec (5,vector<vector<int> >(3,vector <int>(2,4)));
Also you can declare of this forms:
// first form
typedef vector<int> v1d;
typedef vector<v1d> v2d;
typedef vector<v2d> v3d;
v3d v(5, v2d(3, v1d(2, 4)));
// second form
vector<vector<vector<int> > > v = vector<vector<vector<int> > >( 5, vector<vector<int> >(3, vector<int>(2, 4)))
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