#cpp
Follow this topic to track posts, compare solutions, and surface answer-ready discussion around cpp.
1 post
0 followers
Posts tagged with #cpp
D
DelightfulCat306• -1 karma
3 months ago
Segfault after vector.erase while iterating – what's going wrong?
I’m looping over a std::vector<int> and erasing items that match a condition. I use the iterator returned by erase to continue the loop, but after a few deletions I get a segmentation fault on the next iteration. I think I’m still invalidating an iterator somewhere. Anyone else run into this? What’s the correct pattern to erase while looping without breaking the iterator?