C++ 正逆序迭代器
1 #include <iostream> 2 #include <vector> 3 4 using namespace std; 5 6 int main() 7 { 8 vector<string> aa; 9 aa.push_back("A"); 10 aa.push_back("B"); 11 aa.push_back("C"); 12 13 //for (vector<string>::reverse_iterator it = aa.rbegin(); it != aa.rend(); it++) 14 for (auto it = aa.rbegin(); it != aa.rend(); it++) 15 { 16 cout << (*it) << " "; 17 } 18 cout << endl; 19 20 //for (vector<string>::iterator it = aa.begin(); it != aa.end(); it++) 21 for (auto it = aa.begin(); it != aa.end(); it++) 22 { 23 cout << (*it) << " "; 24 } 25 cout << endl; 26 }