2

Hiho everibody. Is there a way to create a pointer to an element of a std::vector but keep the pointer pointing on the same element after deleting one at a lower position?

E.g.: the vector contains 0,1,2,3,4,5 and my pointer points to position 3, so to number 3. Now I want to erase lets say the element at position 1. What I want is that the pointer points automatically at position 2, so still to number 3, without updating it by myself.

Is this possible? Help would be much apreciated. Best regards Ritti

4

1 回答 1

1

std::vector使大多数操作的迭代器无效。如果要保留引用元素的迭代器,请使用另一个容器,例如std::list,它只会使引用已擦除元素的迭代器无效。

于 2013-08-13T14:00:17.607 回答