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));
More Related Contents:
- How to enforce move semantics when a vector grows?
- Invalid operands to binary expression while implementing vector [closed]
- How to Systematically use each item in a Vector [closed]
- How can I insert element to vector instead the element already exists in the vector?
- How do I take values from text file and input into a 2D array? c++
- Does C++11 allow vector?
- Removing item from vector, while in C++11 range ‘for’ loop?
- Is this behavior of vector::resize(size_type n) under C++11 and Boost.Container correct?
- dynamical two dimension array according to input
- Is a moved-from vector always empty?
- C++ unordered_set of vectors
- std::vector, default construction, C++11 and breaking changes
- Is it possible to initialize std::vector over already allocated memory?
- How can I use something like std::vector?
- Is the data in nested std::arrays guaranteed to be contiguous?
- Initializer-list-constructing a vector of noncopyable (but movable) objects
- Compile time triggered range check for std::vector
- Why can’t I create a vector of lambdas (of the same type) in C++11?
- C++ 2 dimensional array with variable size rows
- Why doesn’t emplace_back() use uniform initialization?
- How do I pass multiple ints into a vector at once?
- std::vector resize downward
- Can std::vector emplace_back copy construct from an element of the vector itself?
- Write concurrently vector
- Why do constant expressions have an exclusion for undefined behavior?
- What do I need to do before deleting elements in a vector of pointers to dynamically allocated objects?
- Classes with both template and non-template conversion operators in the condition of switch statement
- stoi and std::to_string on mingw 4.7.1 [duplicate]
- std::enable_if : parameter vs template parameter
- What happen to pointers when vectors need more memory and realocate memory?