print 2d vector c++
#include <iostream>
#include <vector>
int main() {
// Step 1: Declare a 2D vector
std::vector<std::vector<int>> twoDVector;
// Step 2: Initialize the 2D vector with values
twoDVector = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
// Step 3: Access and print elements of the 2D vector using nested loops
for (int i = 0; i < twoDVector.size(); ++i) {
for (int j = 0; j < twoDVector[i].size(); ++j) {
std::cout << twoDVector[i][j] << " ";
}
std::cout << std::endl;
}
return 0;
}