题解 | #迭代器遍历容器#
迭代器遍历容器
https://www.nowcoder.com/practice/0f7ab22e60ee4574a9d9c81412b26595
#include <iostream> // write your code here...... #include <vector> using namespace std; int main() { // write your code here...... vector<int> v; for (int i=1;i<=5;i++){ int is; cin >> is; v.push_back(is); } vector<int>::iterator iter; for (iter = v.begin(); iter != v.end(); ++iter){ cout << *iter << " "; } cout << endl; vector<int>::reverse_iterator ater; for (ater = v.rbegin(); ater != v.rend(); ++ater){ cout << *ater << " "; } cout << endl; return 0; }