zoukankan      html  css  js  c++  java
  • std::advance 给迭代器增加指定偏移量

    template <class InputIterator, class Distance>
      void advance (InputIterator& it, Distance n);
    迭代器辅助函数。
    使迭代器it偏移n,其中n为整数。
    #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::list<int>::iterator it = mylist.begin();
    
      std::advance (it,5);
      std::cout << "The sixth element in mylist is: " << *it << '
    '; 
    
      std::advance (it,-1);
      std::cout << "The fifth element in mylist is: " << *it << '
    '; 
    
      return 0;
    }
    The sixth element in mylist is: 50
    The fifth element in mylist is: 40
    
    
  • 相关阅读:
    网站服务化
    网站服务化
    dubbo 服务化
    dubbo 服务化
    elk 搭建
    poj1840
    poj1840
    poj2299
    poj2299
    poj2388
  • 原文地址:https://www.cnblogs.com/lc-cnblong/p/3196199.html
Copyright © 2011-2022 走看看