vector of vectors c++
vector
#include <vector>
using namespace std;
vector<vector<int>> matrix;
To initialize the vector of vectors with a specific size and value, you can use the following example:
int rows = 3;
int cols = 4;
int initialValue = 0;
vector<vector<int>> matrix(rows, vector<int>(cols, initialValue));
To access and modify elements in the vector of vectors, you can use the following syntax:
int value = matrix[1][2]; // Accessing the element at row 1, column 2
matrix[0][3] = 10; // Modifying the element at row 0, column 3
To iterate through the vector of vectors, you can use nested loops:
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix[i].size(); j++) {
// Access and process matrix[i][j]
}
}