C++ advance()运用案例

C++ advance()运用案例

#include <iterator>
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

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

    list<int>::iterator pos1 = list1.begin();
    cout << "" << *pos1 << endl;

    //
    advance(pos1, 3);
    //
    cout<<""<<*pos1<<endl;
    //
    advance(pos1, -1);
    cout << "" << *pos1 << endl;

    system("pause");
    return 0;
}

 

0
3
2
请按任意键继续. . .

 

代码参考:C++标准库(第2版)

 

 

上一篇:ADVANCE.AI人工智能产品助力中国企业出海墨西哥,开启美洲站


下一篇:L445 This Wearable Device Can Predict Aggressive Outbursts in People with Autism a Minute in Advance