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
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)))