To create a vector of vectors in C++, you can use a vector of vectors of a specific type.
In this example,
vectorOfVectors
with a specific data type.#include <iostream>
#include <vector>
int main() {
std::vector<std::vector<int>> vectorOfVectors = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
for (const auto& innerVector : vectorOfVectors) {
for (const auto& value : innerVector) {
std::cout << value << " ";
}
std::cout << std::endl;
}
return 0;
}
1 2 3 4 5 6 7 8 9
In this tutorial, we learned How to create a Vector of Vectors in C++ language with well detailed examples.