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
|
// reverse_iterator example
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main () {
vector<int> myvector;
for (int i=0; i<10; i++) myvector.push_back(i);
typedef vector<int>::iterator iter_int;
// ? 9 8 7 6 5 4 3 2 1 0 ?
iter_int begin (myvector.begin()); // ^
// ------>
iter_int end (myvector.end()); // ^
//
reverse_iterator<iter_int> rev_end (begin); // ^
// <------
reverse_iterator<iter_int> rev_iterator (end); // ^
for ( ; rev_iterator < rev_end ; ++rev_iterator)
cout << *rev_iterator << " ";
cout << endl;
return 0;
}
|