题解 | #迭代器遍历容器#
迭代器遍历容器
https://www.nowcoder.com/practice/0f7ab22e60ee4574a9d9c81412b26595
#include <iostream> // write your code here...... #include <vector> using namespace std; int main() { vector<int> v; int a = 5, i =0; v.resize(a); while(a--) cin >> v[i++]; vector<int>::iterator it = v.begin(); while(it != v.end()) { cout << *it << " "; it++; } cout <<endl; vector<int>::reverse_iterator it1 = v.rbegin(); while(it1 != v.rend()) { cout << *it1 << " "; it1++; } cout << endl; return 0; }