How can I resize a 2D vector of objects given the width and height?
You have to resize the outer and inner vectors separately.
myVector.resize(n);
for (int i = 0; i < n; ++i)
myVector[i].resize(m);
You don't need to create external loop to resize a 2 dimensional vector (matrix). You can simply do the following one line resize()
call:
//vector<vector<int>> M;
//int m = number of rows, n = number of columns;
M.resize(m, vector<int>(n));
Hope that helps!