Return to Snippet

Revision: 35659
at November 11, 2010 19:30 by browny


Initial Code
// distance example
#include <iostream>
#include <iterator>
#include <list>
using namespace std;

int main () {
  list<int> mylist;
  for (int i=0; i<10; i++) mylist.push_back (i*10);

  list<int>::iterator first = mylist.begin();
  list<int>::iterator last = mylist.end();

  cout << "The distance is: " << distance(first,last) << endl;

  return 0;
}

Initial URL
http://www.cplusplus.com/reference/std/iterator/distance/

Initial Description

                                

Initial Title
Get index from STL container iterator

Initial Tags

                                

Initial Language
C++