What happens if you increment an iterator that is equal to the end iterator of an STL container

前端 未结 8 1526
别那么骄傲
别那么骄傲 2020-11-27 05:46

What if I increment an iterator by 2 when it points onto the last element of a vector? In this question asking how to adjust the iterator to an STL container by 2 elements t

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 06:45

    The code that Marijn suggests is just slightly wrong (as curiousguy pointed out).

    The correct version of the last line is:

    bool isPastEnd = it >= vec.end();
    

提交回复
热议问题