#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
    list<int> coll;

    for (int i = 1; i <= 9; ++i)
    {
        coll.push_back(i);
    }

    list<int>::iterator pos = coll.begin();
    cout << *pos << endl;

    advance(pos, 3);
    cout << *pos << endl;

    advance(pos, -1);
    cout << *pos << endl;

    int size = distance(coll.begin(), coll.end());

    printf("size is %d\n", size);

    getchar();
    return 0;
}

运行结果:

STL中的distance和advance的简单用法

参考:http://www.programlife.net/stl-iterator-funcation-advance.html

     http://www.programlife.net/stl-iterator-funcation-distance.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-06-03
  • 2022-02-27
  • 2022-12-23
  • 2021-07-25
  • 2021-10-16
猜你喜欢
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-07-15
  • 2021-09-02
相关资源
相似解决方案