关于代码里map的删除,有一点困惑:
在删除前用iterator保存位置,对map进行插入或删除后,iterator是否有效.
看完标准后释然,直接上标准:
23.1.2.8:The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.
本文探讨了C++ STL中map容器的迭代器在进行插入或删除操作后的有效性问题。根据C++标准文档,插入操作不会影响已存在的迭代器的有效性,而删除操作仅使指向被删除元素的迭代器失效。
347

被折叠的 条评论
为什么被折叠?



