resizing multidimensional vector

前端 未结 5 467
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 17:39

How to resize multidimensional vector such as:

  vector  > > array; 

For example, I need arr

相关标签:
5条回答
  • 2020-12-31 17:46

    You should resize all the nested vectors one by one. Use nested for loops or recursion.

    0 讨论(0)
  • 2020-12-31 17:54

    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-31 17:54

    see also Boost.MultiArray

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

    0 讨论(0)
  • 2020-12-31 17:55
    array.resize(3,vector<vector<custom_type> >(5,vector<custom_type>(10)));
    
    0 讨论(0)
  • 2020-12-31 18:06

    I would make a custom container containing a vector of vectors (of ... per dimension) and resize with resize-functions per dimension. This way you can put the invariant of equal size per dimension in one place. The actual resizing can then be done in a loop according to dimension.
    There will be a bit of work involved in making public what needs to be accessed (operator[],...)

    0 讨论(0)
提交回复
热议问题