Linked Questions
24 questions linked to/from Remove elements of a vector inside the loop
0 votes
2 answers
273 views
Erasing data in vector via loop causing breakpoints [duplicate]
I have a vector of class objects (bullets) and it works for the most part. But as soon as I try to delete the bullets it loops back and then causes a breakpoint. "basic game.exe has triggered a ...
0 votes
1 answer
1k views
Best practice for deleting vector of pointers while iterating [duplicate]
When iterating through an STL::vector of pointers, what is the best practice for deleting objects along the way? I understand the erase-remove idiom. But since the vector contains pointers, I am ...
0 votes
1 answer
525 views
Vector iterator is not incrementable [duplicate]
Why am I getting a Vector iterator is not incrementable error in this code? for (vector<vector<Point>>::iterator it = contours.begin(); it != contours.end(); ++it) { if (contourArea(*...
-2 votes
1 answer
315 views
How do I remove an element from a vector reference? [duplicate]
I am iterating through a map which has the vector as the V parameter map<SomeKey, vector<shared_ptr<SomeObject>> I am iterating over to remove all instances of SomeObject contained in ...
0 votes
0 answers
162 views
How does erase work on a vector? [duplicate]
im new to C++. I want to know how to erase an element from a vector passed by reference, where the value of Length (function of my Vector3D object) returned is less than the int parameter passed to ...
1 vote
0 answers
127 views
C++ erase last element of a vector using erase(Iterator) [duplicate]
I have this code I made up to explain my problem: #include <iostream> #include <vector> void PrintVector (const std::vector<int> & vec) { std::cout << "vector contains:...
-2 votes
1 answer
94 views
Remove matched elements from 2 different vectors [duplicate]
How can i remove matched elements in c++ while keeping the same order ? i found similar question here but they sort the elements while i want to keep the order for example i have v1{1,2,3,4} , v2{8,6,...
126 votes
7 answers
179k views
How can you erase elements from a vector while iterating?
I want to clear a element from a vector using the erase method. But the problem here is that the element is not guaranteed to occur only once in the vector. It may be present multiple times and I need ...
0 votes
4 answers
573 views
How do I conditionally skip a for loop's post operation in c++ 11?
I have a for loop that iterates through a vector of objects. If an object doesn't meet a condition, I would like to reiterate the same object through the loop until it meets the condition. int ...
2 votes
2 answers
2k views
C++ Erase key-value in map while iterating over it
The following C++ code seems to work, and I'm curious to learn how: std::map<char,char> mymap; mymap['a'] = 'A'; mymap['b'] = 'B'; mymap['c'] = 'C'; mymap['d'] = 'D'; mymap['e'] = 'E'...
-1 votes
3 answers
3k views
C++ for loop skipping elements of a vector?
I'm tasked with creating a vector of 'x' numbers and finding the prime numbers in that vector using the "Sieve of Eratosthenes." I iterated through the vector to replace all of the non-prime elements ...
0 votes
1 answer
4k views
No matching member function for call to 'erase' while erasing a value from vector
I am trying to write this code but this is giving the error No matching member function for call to 'erase'clang(ovl_no_viable_member_function_in_call) stl_vector.h(1317, 7): Candidate function not ...
4 votes
2 answers
2k views
vector::erase with pointer member
I am manipulating vectors of objects defined as follow: class Hyp{ public: int x; int y; double wFactor; double hFactor; char shapeNum; double* visibleShape; int xmin, xmax, ymin, ymax; Hyp(int xx,...
0 votes
2 answers
1k views
Deleting a vector element in a loop, based upon a conditional statement
In this code snippet Update() returns a boolean, if it returns false I would like to delete the element from the vector. However, this produces a run-time error of debug assertion failed. The ...
1 vote
2 answers
2k views
Segmentation fault when erasing last element in vector
I'm trying to erase the last element in the vector using iterator. But I'm getting segmentation fault when erasing the element. Below is my code: for (vector<AccDetails>::iterator itr = ...