Resize a multidimensional vector

How to resize a multidimensional vector, for example:

vector <vector <vector <custom_type> > > array; 

For example, do I need an array [3] [5] [10]?

+6
c ++ stl
source share
5 answers

You must resize all nested vector one by one. Use nested for loops or recursion.

+4
source share
 array.resize(3,vector<vector<custom_type> >(5,vector<custom_type>(10))); 
+8
source share

see also Boost.MultiArray

Boost.MultiArray provides a generic N-dimensional array concept definition and common implementations of that interface.

+5
source share

I did it))

 array.resize(3); for (int i = 0; i < 3; i++) { array[i].resize(5); for (int j = 0; j < 5; j++) { array[i][j].resize(10); } } 
+4
source share

I would make a custom container containing a vector of vectors (from ... for a dimension) and resize using the size options for each dimension. Thus, you can place an invariant of equal size on a dimension in one place. Actual resizing can be done in a loop according to the measurement.
There will be a little work related to publishing what you need to access (operator [], ...)

+2
source share

All Articles