c++ std::advance

 

// advance example
#include <iostream>     // std::cout
#include <iterator>     // std::advance
#include <list>         // std::list

int main () {
  std::list<int> mylist;
  for (int i=0; i<10; i++){
      mylist.push_back (i*10);
      std::cout<<i*10<<'\n';
  }
  std::list<int>::iterator it = mylist.begin();

  std::advance (it,5);

  std::cout << "The sixth element in mylist is: " << *it << '\n';

  return 0;
}

输出

0
10
20
30
40
50
60
70
80
90
The sixth element in mylist is: 50

 

posted @ 2019-04-26 01:18  anobscureretreat  阅读(333)  评论(0编辑  收藏  举报