在下面的循环中,我使用了一个预先计算好的结束迭代器:
std::list::iterator end = MyList.end();
for (std::list::iterator it = MyList.begin(); it != end ;)
it = MyList.erase(it);
当删除 std::list 中的元素时,MyList.end() 是否可以更改其值以便 end != MyList.end()
不再存在?
最佳答案
没有。
n3376 23.3.5.4
iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last);
Effects: Invalidates only the iterators and references to the erased elements.
关于c++ - 删除时 std::list end() 迭代器位置是否改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17335313/