C++ 迭代器失效 ++报错

Posted 软件工程小施同学

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++ 迭代器失效 ++报错相关的知识,希望对你有一定的参考价值。

迭代器失效,迭代器++报错

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f5a4be6ffb4 in std::_Rb_tree_increment(std::_Rb_tree_node_base*) () from /usrb/x86_64-linux-gnubstdc++.so.6
[Current thread is 1 (Thread 0x7f5a362f4700 (LWP 45441))]
(gdb) where
#0  0x00007f5a4be6ffb4 in std::_Rb_tree_increment(std::_Rb_tree_node_base*) () from /usrb/x86_64-linux-gnubstdc++.so.6
#1  0x0000559cce8be9c8 in std::_Rb_tree_iterator<.....>::operator++ (this=<synthetic pointer>)
    at /usr/include/c++/7/bitsl_tree.h:295

原因:

在用迭代器执行erase,insert等函数时,迭代器的指针会被释放掉,从而不能继续使用,如果继续使用,则会报错

加锁

以上是关于C++ 迭代器失效 ++报错的主要内容,如果未能解决你的问题,请参考以下文章

C++ 迭代器失效 ++报错

13. 迭代器失效问题迭代器失效底层原理及实现

c++中迭代器的问题为啥这样会报错?

C++关于使用流迭代器>>和<<符号报错问题

C++ set find erase 报错 崩溃

迭代器原理