#include <cstdio>
#include <list>
#include <vector>
#include <iterator>
int main(){
std::list< std::vector<int> > li;
li.push_back(std::vector<int>());
li.push_back(std::vector<int>());
std::vector<int> v3(3);
v3.push_back(1);
v3.push_back(2);
v3.push_back(3);
li.push_back(v3);
for (std::list<std::vector<int> >::iterator it1 = li.begin(); it1 != li.end(); ++it1){
std::vector<int>::iterator it2;
for (it2 = (*it1).begin(); it2 != (*it1).end(); ++ it2){
std::printf("element: %d\n",(*it2));
}
}
return OK;
}
新しいC++11構文に精通している場合は、さらに簡単になる可能性があります。
std::list< std::vector<int> > li;
li.push_back({1, 2, 3});//push_back vector
li.push_back({4, 5, 6});//again, vector implicitly
for (auto &v : li)
{
//even better auto const since we need read only access to elements
for (auto const &i : v)
std::printf("element: %d\n",i);
}