c++ initialize multidimensional vector

#include <iostream>
#include <vector>

int main() {
    // Specify dimensions of the 2D vector
    int rows = 3;
    int cols = 4;

    // Initialize a 2D vector with specified dimensions and default values (0 in this case)
    std::vector<std::vector<int>> myVector(rows, std::vector<int>(cols, 0));

    // Access and modify elements in the 2D vector
    myVector[1][2] = 42;

    // Display the contents of the 2D vector
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            std::cout << myVector[i][j] << " ";
        }
        std::cout << "\n";
    }

    return 0;
}