Traverse a List Using an Iterator : list iterator « List « C++






Traverse a List Using an Iterator

Traverse a List Using an Iterator
  
#include <iostream>
#include <list>
using namespace std;

typedef list<int> IntegerList;

int main()
{
       IntegerList intList;

       for (int i = 1; i <= 10; ++i)
               intList.push_back(i * 2);

       for (IntegerList::const_iterator ci = intList.begin(); ci != intList.end(); ++ci)
               cout << *ci << " ";

       return 0;
}
  
    
  








Related examples in the same category

1.Use iterator to loop through all elements in a list
2.Use iterator to change all elements in a list
3.Loop through list back and forth
4.Use reverse_iterator and iterator with list
5.Move list iterator using ++