#include #include #include struct test { int n; std::string str; }; int main(void) { test t; std::list l; t.str="overflow"; t.n = 1; /* Add this item to the back */ l.push_back(t); t.str="test"; t.n = 2; /* Add this item to the back */ l.push_back(t); /* Access it through iterators */ for(std::list::iterator it = l.begin(); it != l.end(); it++) { std::cout << "item: " << (it)->n << " str: " << (it)->str << std::endl; } t.str="stack"; t.n = 0; /* add this item first */ l.push_front(t); /* access it directly through an iterator */ std::cout << "item: " << (*l.begin()).n << " str: " << (*l.begin()).str << std::endl; }