1、front_insert_iterator——用于创建一个可自增减并通过push_front赋值的迭代器对象
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
list<int> L;
L.push_front(3);
front_insert_iterator<list<int> > iL(L);
*iL++ = 0;
*iL++ = 1;
*iL++ = 2;
copy(L.begin(), L.end(),
ostream_iterator<int>(cout, " "));
}
运行结果:
// 2 1 0 3
2、back_inserter——使用 push_back 实现一种插入器
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main()
{
deque<int> d;
back_inserter(d) = 100;
back_inserter(d) = 200;
copy(d.begin(),d.end(),
ostream_iterator<int>(cout," "));
cout << endl;
copy (d.begin(), d.end(),
back_inserter(d));
copy(d.begin(),d.end(),
ostream_iterator<int>(cout," "));
cout << endl;
return 0;
}
运行结果:
// 100 200
// 100 200 100 200
3、back_insert_iterator——创建使用 push_back 实现插入的迭代器
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
list<int> L;
L.push_back(3);
back_insert_iterator<list<int>> iL(L);
*iL++ = 0;
*iL++ = 1;
*iL++ = 2;
copy(L.begin(), L.end(),
ostream_iterator<int>(cout, " "));
}
运行结果:
// 3 0 1 2
4、reverse_iterator——反向迭代器,这类迭代器实现向后遍历,而不是向前遍历,由 rbegin 和 rend 成员函数返回
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
vector<int> v(10);
iota (v.begin(),v.end(),1);
copy (v.begin(),v.end(),
ostream_iterator<int>(cout," "));
cout << endl;
vector<int>::reverse_iterator r = v.rbegin();
while ( r != v.rend() )
cout << *r++ << " ";
cout << endl;
return 0;
}
运行结果:
// 1 2 3 4 5 6 7 8 9 10
// 10 9 8 7 6 5 4 3 2 1
除非注明,文章均为CppLive 编程在线原创,转载请注明出处,谢谢。




博客互访啦。
同时欢迎来我的化妆博客www.wxhzs.com坐坐,给点宝贵意见
谢谢,热烈欢迎哦~ 🙂