#include <bits\stdC++.h>
using namespace std;
void show(int x){
  printf("%-2d",x);
}
int main(int argc, char const *argv[]) {
  vector<int> v;
  v.push_back(2);
  v.push_back(3);
  v.push_back(4);
  /*遍历*/
  for_each(v.begin(),v.end(),show);
  printf("\n");
  //改变一个向量的迭代器就可以改变 向量内容
  vector<int>::iterator v1 = v.begin();
  /*此时迭代器v1 代表的位置是 v.begin() */
  *v1 = v.back();
  for_each(v.begin(),v.end(),show);
  return 0;
}

迭代器的使用

相关文章: