Dereference and Increment on vector Iterators

Dereference and Increment on vector Iterators

  • The operations on iterator types let us retrieve element to which an iterator refers and let us move an iterator from one element to another.

  • Iterator types use the dereference operator (the * operator) to access the element to which the iterator refers:
*iter=0;    //The effect of this statement is to assign 0 to that element
  • The dereference operator returns the element that the iterator currently denotes.Assuming iter refers to the first element of the vector,then *iter is the same element as ivec[0].The effect of this statement is to assign 0 to that element.

A Program that Uses Iterators

  • Assume we had a vector named ivec and we wanted to reset each of its elements to zero.We might do so by using a subscript:
for(vector<int>::size_type ix=0;ix!=ivec.size();++ix)
    ivec[ix]=0;     //reset all the elements in ivec to 0
  • A more typical way to write this loop would use iterators:
for(vector<int>::iterator iter=ivec.begin();iter!=ivec.end();++iter
The FirstThe Second
subscript['sab skript]下标
norm范数

转载于:https://www.cnblogs.com/hugeng007/p/9351729.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值