To create a list of empty lists in C++ using std::list, you can initialize a list of lists with empty lists as elements.
In this example,
header for using std::list.list_of_lists
using std::list to hold empty lists.#include <iostream>
#include <list>
#include <vector>
int main() {
std::list<std::list<int>> list_of_lists(3);
for (auto& inner_list : list_of_lists) {
inner_list = {};
}
for (const auto& inner_list : list_of_lists) {
for (const auto& value : inner_list) {
std::cout << value << ' ';
}
std::cout << '\n';
}
return 0;
}
In this tutorial, we learned How to create a List of Empty Lists in C++ language with well detailed examples.