Does pop_back() really invalidate *all* iterators on an std::vector?

前端 未结 11 1571
半阙折子戏
半阙折子戏 2021-01-05 06:26
std::vector ints;

// ... fill ints with random values

for(std::vector::iterator it = ints.begin(); it != ints.end(); )
{
    if(*it < 10)
         


        
11条回答
  •  孤城傲影
    2021-01-05 06:52

    Check out the information here (cplusplus.com):

    Delete last element

    Removes the last element in the vector, effectively reducing the vector size by one and invalidating all iterators and references to it.

提交回复
热议问题