码迷,mamicode.com
首页 > 其他好文 > 详细

reverse iterator

时间:2014-09-11 18:56:12      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   ar   for   2014   div   log   

bubuko.com,布布扣

Problem 1:

vector<int> coll = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

vector<int>::const_iterator pos = find (coll.cbegin(), coll.cend(),5);

cout << "pos: " << *pos << endl;

vector<int>::const_reverse_iterator rpos(pos);

cout << "rpos: " << *rpos << endl;

This program has the following output:

pos: 5

rpos: 4

Same position but its value is changed; this can use the pos in the diagram to illustrate it.

bubuko.com,布布扣

Problem 2:

deque<int> coll = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

deque<int>::const_iterator pos1;

pos1 = find (coll.cbegin(), coll.cend(), 2); // value

deque<int>::const_iterator pos2;

pos2 = find (coll.cbegin(), coll.cend(), 7); // value

for_each (pos1, pos2, print); // operation

deque<int>::const_reverse_iterator rpos1(pos1);

deque<int>::const_reverse_iterator rpos2(pos2);

for_each (rpos2, rpos1, print); // operation

The program is as follows:

2 3 4 5 6

6 5 4 3 2

It seems the behavior of the problem 2 is not same with problem 1.

This can use the pos1, pos2 in the diagram to illustrate it.

reverse iterator

标签:blog   http   io   os   ar   for   2014   div   log   

原文地址:http://www.cnblogs.com/Cmpl/p/3966886.html

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