码迷,mamicode.com
首页 > 编程语言 > 详细

C++ deque const_iterator const_reverse_iterator运用实例

时间:2019-12-29 16:33:10      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:std   oid   代码   运用   eve   pac   system   pos   col   

C++ deque const_iterator const_reverse_iterator运用实例

#include <iterator>
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

void print1(int elem1)
{
    cout << "" << elem1 << endl;
}

int main()
{
    deque<int> deque1 = {1,2,3,4,5,6,7,8,9};
    deque<int>::const_iterator c_iter1;
    c_iter1 = find(deque1.cbegin(),deque1.cend(),2);

    deque<int>::const_iterator c_iter2;
    c_iter2 = find(deque1.cbegin(), deque1.cend(), 7);

    for_each(c_iter1, c_iter2, print1);
    cout << endl;

    deque<int>::const_reverse_iterator r_iter1(c_iter1);
    deque<int>::const_reverse_iterator r_iter2(c_iter2);
    for_each(r_iter2,r_iter1,print1);
    cout << endl;

    system("pause");
    return 0;
}

2
3
4
5
6

6
5
4
3
2

请按任意键继续. . .

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

C++ deque const_iterator const_reverse_iterator运用实例

标签:std   oid   代码   运用   eve   pac   system   pos   col   

原文地址:https://www.cnblogs.com/herd/p/12115275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!