#include <iostream>
#include <vector>
int main(){
std::vector<std::vector<int>> vec2d;
// Resize to 4 rows
vec2d.resize(4);
// Resize each row to 2,3,4,5 columns
int value = 2;
for (auto& row : vec2d) {
row.resize(value++);
}
std::cout << "The number of rows in vector is: " << vec2d.size() << std::endl;
std::cout << "The number of columns in vec2d[0] is: " << vec2d[0].size() << std::endl;
std::cout << "The number of columns in vec2d[1] is: " << vec2d[1].size() << std::endl;
// Fill and print the vec2d
value = 1;
for (const auto& row : vec2d) {
for (int col : row) {
std::cout << value++ << " ";
}
std::cout << std::endl;
}
}
/*
run:
The number of rows in vector is: 4
The number of columns in vec2d[0] is: 2
The number of columns in vec2d[1] is: 3
1 2
3 4 5
6 7 8 9
10 11 12 13 14
*/