c++ - 迭代器是否失效?

标签 c++ iterator

迭代器是否在以下时间后失效:

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().

来源:http://www.cplusplus.com/reference/string/string/erase/

关于c++ - 迭代器是否失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2984206/

相关文章:

c++ - 为什么对函数 "sample_mean"的调用不明确?

c++ - 声明与(方法)不兼容 - 指针

c++ - 将一个txt文件读入一个字符串

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

iterator - 迭代时返回集合元素的双索引

c++ - 多个 tcp 套接字,一个停止

python - 迭代器只能迭代一次吗?

Java内部类迭代器问题

c++ - 在 C++ 中释放内存期间,迭代器与指针有何不同

c++ - 遍历 std::set 中包含的所有三重不同值?