1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <iostream> #include <sstream> #include <fstream> #include <set> #include <vector> #include <list> #include <map> #include <string> #include <iterator> // std::front_inserter #include <algorithm>
using namespace std;
int main() { cout << "反向迭代器:" << endl; vector<int> ivec; ivec.push_back(1); ivec.push_back(2); ivec.push_back(3);
ostream_iterator<int> output(cout,","); copy(ivec.begin(), ivec.end(), output);
cout << "用反向迭代器逆序输出: " << endl; for (vector<int>::reverse_iterator it = ivec.rbegin(); it != ivec.rend(); ++it) { cout << *it << ","; } cout << "用反向迭代器拷贝到输出流:" << endl; copy(ivec.rbegin(), ivec.rend(), output);
return 0; }
|