iterators can't access problems properly

前端 未结 3 1677
攒了一身酷
攒了一身酷 2021-01-20 11:27

I am trying to access the element of a vector using the iterator. But I get strange outputs.

std::vector ivec{ 7, 6 , 8, 9} ; 

std::vector

        
3条回答
  •  礼貌的吻别
    2021-01-20 11:40

    end iterators are not iterators that you can de-reference. They point past the last element into the container. There's a good reason why this needs to be true; but long and short, the end iterator does not actually point to any element. If you want the last element, you need to decrement the end iterator.

提交回复
热议问题