karthik karthik - 22 days ago 8
C++ Question

Traverse a List Using an Iterator?

I need sample for traversing a list using C++.

Answer

The sample for your problem is as follows

  #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;
  }
Comments