题解 | #迭代器遍历容器#
迭代器遍历容器
https://www.nowcoder.com/practice/0f7ab22e60ee4574a9d9c81412b26595
#include <bits/stdc++.h>
using namespace std;
int main() {
// write your code here......
vector<int>::iterator it1;
vector<int>::reverse_iterator it2;
vector <int> v1(5);
for (it1 = v1.begin(); it1 != v1.end();) {
cin >> *it1;
it1++;
}
for (it1 = v1.begin(); it1 != v1.end();) {
cout << *it1 << " ";
it1++;
}
cout << endl;
for (it2 = v1.rbegin(); it2 != v1.rend(); it2++) {
cout << *it2 << " ";
}
return 0;
}
查看10道真题和解析