const_iterator学习

转自:https://www.cnblogs.com/greatverve/archive/2012/09/12/const-iterator.html

1.介绍

如果传递过来一个const类型的容器,那么只能用const_iterator来遍历。 

void Method(const vector<int> vInt)
{
  vector<int>::const_iterator iter;
}

iterator,const_iterator作用:遍历容器内的元素,并访问这些元素的值。iterator可以改元素值,但const_iterator不可改。

迭代器也可以作为函数的形参,比如说sort(vec.begin(), vec.end()),一般就会将迭代器作为参数传递进去。

 

posted @ 2022-11-05 21:53  lypbendlf  阅读(95)  评论(0编辑  收藏  举报