Linked Questions
12 questions linked to/from How to delete an element from a vector while looping over it?
2 votes
6 answers
219 views
possible inconsistency in std::vector while erasing an element [duplicate]
while debugging a vector, I see an inconsistency. Assume the following code which tries to remove an entry from a vector which has only one element #include <iostream> #include <vector> ...
2 votes
3 answers
248 views
Deleting a pointer from a vector [duplicate]
I use a vector of shared pointers to contain some game characters called customer. typedef std::shared_ptr<Customer> customer; std::vector<customer> customers; customers.push_back(...
-1 votes
1 answer
109 views
vector loop weird behavior C++ [duplicate]
I'm removing duplicate integers from the vector; the loop I made is working as intended, but only if I add Break; inside the ' if ' statement, or it will give wrong output. Can someone explain why is ...
-1 votes
1 answer
78 views
For loop over string ignores characters [duplicate]
So I have simple JSON string that I'm iterating through with a for loop (don't ask why I'm not using a json parser). In this loop I want to kick out {, } and '' (the misplaced } is just there for ...
2 votes
4 answers
3k views
Safe way to continuously erase from a std::vector?
I thought the following code would work but it crashes when the target widget is at the end of the vector. for(std::vector<AguiWidget*>::iterator it = children.begin(); it != children....
4 votes
1 answer
8k views
Moving elements from one vector to another using erase-remove paradigm
This question clearly articulates how to move contents from one std::vector to another. In short, there is a std::move call required to physically move the memory, while there is also a std::erase ...
-5 votes
4 answers
891 views
How to erase elements in STL vector without copying iterator and without memory leakage?
This is the edited code vector<vector<int> > vec; vector<vector<int> >::iterator vit; vector<int>::iterator it; for ( vit = vec.begin(); vit != vec.end(); ++vit) { ...
0 votes
1 answer
2k views
I am getting this ERROR: AddressSanitizer: negative-size-param: (size=-8)
When removing the given elements from the given array, I keep getting an error. This is my code, I am not sure where I the error is: int removeElement(vector<int>& nums, int val) { ...
-1 votes
1 answer
753 views
Vector erase memory access error [duplicate]
I just recently started experimenting with vectors and I keep running into this problem when erasing a spot in the vector. Once it executes the erase() function it causes the application to crash and ...
0 votes
0 answers
692 views
Access violation reading location 0x00000088 C++
I cannot for the life of me figure out this error Access violation reading location 0x00000088, I am programming a script that controls the leds on my keyboard, and this error pops up after only about ...
1 vote
3 answers
111 views
Removing one element of a vector while in a loop
for (Shape *i : shapes) { for (Shape *j : shapes) { if (i != j) { if (check(i,j)){ shapes.erase(remove(shapes.begin(), shapes.end(), i), shapes.end()); this ...
1 vote
1 answer
47 views
Pushing five object pointers in one scope, then checking if the bool of the object is false, gives an error
I am working on a game for my University project and came across a problem with pointers. I have a vector of bullets that has every bullet checked for collisions. But, when I try to spawn 5 bullets at ...