c++ init multidimensional vector
Initializing Multidimensional Vector in C++
To initialize a multidimensional vector in C++, you can follow these steps:
Include the Necessary Header File:
cpp #include <vector>
Declare the Multidimensional Vector:
cpp std::vector<std::vector<int>> myVector;
Set the Size of Each Dimension:
cpp int rows = 3; int cols = 4; myVector.resize(rows, std::vector<int>(cols));
Access and Modify Elements:
cpp myVector[0][0] = 1; myVector[1][2] = 5;
In this example, we've initialized a 2D vector of integers with 3 rows and 4 columns. You can modify the size and data type according to your requirements.