迭代器是否在以下时间后失效:
string b "Some string";
auto beg_ = b.begin();
auto end_ = b.end();
b.erase(beg_);
最佳答案
是的,但是 erase 会返回一个有效的迭代器,您可以使用它来继续循环:
For the remaining members, the function returns an iterator of member type string::iterator referring to the character that now occupies the position of the first character erased, or, if no such character exists, returns end().
关于c++ - 迭代器是否失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2984206/