A 2D vector is a vector of vector. Like 2D arrays, we can declare and assign values to 2D matrix
1 2 3 4 5 6 7 8 9
Like Java’s jagged arrays, each row of 2D vector can contain different number of columns.
1 2 4 5 6 7 8 9 10
Exercise Problem : Define the 2D vector with different sizes of column input by user.
Input : Number of rows : 5 Number of columns in rows : 2 3 4 5 1 Output : 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 Input : Number of rows : 3 Number of columns in rows : 3 2 1 Input : 3 3 2 1 Output : 1 2 3 1 2 1
First we take the input of row and and take the input of column of every row.
Now the initialize the memory of every row by the size of column.
1 2 3 4 5 1 2 3 1 2 3 4 1 2 1
This article is contributed by Amit Verma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- User Defined Literals in C++
- Function Interposition in C with an example of user defined malloc()
- User defined derived data types in C++
- How to create an unordered_map of user defined class in C++?
- How to implement user defined Shared Pointers in C++
- Multi-set for user defined data type
- How to create an unordered_set of user defined class or struct in C++?
- vector::empty() and vector::size() in C++ STL
- vector :: cbegin() and vector :: cend() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector::front() and vector::back() in C++ STL
- vector::push_back() and vector::pop_back() in C++ STL
- vector::begin() and vector::end() in C++ STL
- vector::at() and vector::swap() in C++ STL
- C++ map having key as a user define data type