Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <iostream>
- #include <string>
- struct test {
- int n;
- std::string str;
- };
- int main(void) {
- test t;
- std::list<test> 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<test>::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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement