How can I resize a 2D vector of objects given the width and height?

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

Leave a Comment