Lecture overview -- Keyboard shortcut: 'u'  Previous page: Iterators seen as generalized pointers -- Keyboard shortcut: 'p'  Next page: Different classifications of iterators -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 5 - Page 18 : 39
Notes about C++
Templates and The Standard Library
Example uses of iterators - basis stuff

We show a simple, practical example of iterators and their use

#include <iostream>
#include <string>
#include <vector>

int main(){
  using namespace std;

  vector<double> vd;

  for(int i = 1; i <= 10; i++)
     vd.push_back(i + i/10.0);

  typedef vector<double>::iterator vec_it;

  vec_it it1 = vd.begin();
 
  while(it1 != vd.end()){
     cout << *it1 << " ";   // 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 11 
     ++it1;
  }
}

A really simple example of iterators.

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/iterators/rit-1.cppThe same program using a reverse iterator.