Advance iterator for the std::vector std::advance VS operator +?

前端 未结 7 1221
萌比男神i
萌比男神i 2021-02-07 07:36

I found myself writing the following a lot:

int location =2;
vector vec;
vector::iterator it=vec.begin();

/..../
std::advance(it, location         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 07:43

    std::advance works on non-random iterators too while the += version on works on random access sequences (vectors and the like).

提交回复
热议问题