2d array using vector

#include <iostream>
#include <vector>

int main() {
    // Step 1: Define the dimensions of the 2D array
    int rows = 3;
    int cols = 4;

    // Step 2: Declare a vector of vectors to represent the 2D array
    std::vector<std::vector<int>> myArray;

    // Step 3: Resize the vector to the specified number of rows
    myArray.resize(rows);

    // Step 4: Iterate over each row and resize it to the specified number of columns
    for (int i = 0; i < rows; ++i) {
        myArray[i].resize(cols);
    }

    // Step 5: Initialize the 2D array with values (optional)
    int value = 1;
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            myArray[i][j] = value;
            ++value;
        }
    }

    // Step 6: Access and print the elements of the 2D array
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            std::cout << myArray[i][j] << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}