将const_iterator复制到std :: string以保存位置

时间:2017-05-27 10:54:33

标签: c++ string c++11 iterator

在执行++操作时,从std :: string类创建const_iterator的快照而不使其失效是否合法。

例如: 如果想要在字符串中保存位置,那么我复制当前的const_iterator:

std::string::const_iterator it = prev;

现在我的解析器继续使用prev ++。它仍然有效并指向prev的先前位置吗?

1 个答案:

答案 0 :(得分:3)

  

它是否仍然有效并指向prev的上一个位置?

是的,只要std::string未被更改(以operator[]at()以外的方式),那是合法的并且迭代器快照仍然有效。

相关问题