List vector c++
时间: 2023-10-14 17:27:34 浏览: 145
In C++, a list is a container that stores elements in a linked list. To create a list of vectors, you can use the following code:
```
#include <iostream>
#include <list>
#include <vector>
int main() {
std::list<std::vector<int>> mylist;
// Create a vector and add some elements
std::vector<int> v1 = {1, 2, 3};
std::vector<int> v2 = {4, 5, 6};
// Add the vectors to the list
mylist.push_back(v1);
mylist.push_back(v2);
// Print the elements in the list
for (auto& v : mylist) {
for (auto& i : v) {
std::cout << i << " ";
}
std::cout << "\n";
}
return 0;
}
```
In this example, we create a list of vectors called `mylist`, and add two vectors `v1` and `v2` to the list using the `push_back` method. We then iterate over the elements in the list and print them to the console.
阅读全文