Posted By

browny on 11/11/10


Tagged

index iterator stl


Versions (?)

Get index from STL container iterator


 / Published in: C++
 

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

  1. // distance example
  2. #include <iostream>
  3. #include <iterator>
  4. #include <list>
  5. using namespace std;
  6.  
  7. int main () {
  8. list<int> mylist;
  9. for (int i=0; i<10; i++) mylist.push_back (i*10);
  10.  
  11. list<int>::iterator first = mylist.begin();
  12. list<int>::iterator last = mylist.end();
  13.  
  14. cout << "The distance is: " << distance(first,last) << endl;
  15.  
  16. return 0;
  17. }

Report this snippet  

You need to login to post a comment.