iterator of list integers : list iterator « list « C++ Tutorial






#include <iostream>
#include <list>
using namespace std;
   
int main()
{
  list<int> lst;
  int i;
   
  for(i=0; i<10; i++) lst.push_back(i);
   
  cout << "Size = " << lst.size() << endl;
   
  list<int>::iterator p = lst.begin();
  while(p != lst.end()) {
    cout << *p << endl;
    p++;
  }
   
  p = lst.begin();
  while(p != lst.end()) {
    *p = *p + 100;
    p++;
  }
   
  p = lst.begin();
  while(p != lst.end()) {
    cout << *p << " ";
    p++;
  }
   
  return 0;
}








17.9.list iterator
17.9.1.Use iterator to loop through all elements in a list
17.9.2.Use iterator to change all elements in a list
17.9.3.Loop through list back and forth
17.9.4.Use reverse_iterator and iterator with list
17.9.5.iterator of list integers
17.9.6.List iterator for certain type list
17.9.7.Move list iterator using ++