使用反向迭代适配器进行迭代
How to do it...
#include <iostream> #include <list> #include <iterator>using namespace std;int main() { list<int> l {1, 2, 3, 4, 5};copy(l.rbegin(), l.rend(), ostream_iterator<int>{cout, ", "}); cout << '\n';copy(make_reverse_iterator(end(l)), make_reverse_iterator(begin(l)), ostream_iterator<int>{cout, ", "}); cout << '\n'; }5, 4, 3, 2, 1, 5, 4, 3, 2, 1,
How it works...

Last updated