Im making a go fish card game and i have this function to remove a card from one deck and add it to another. I have it going through the list of the loser (the person who has to give away the card if they have it) If the card is not there then the function doesn't remove any cards but if the card is found then it infinite loops. first of all this for loop shouldn't loop infinitely right? And also this is how the .remove() works for stl lists?
After remove() pointer p will be invalidated and trying to increment it will lead to unexpecter results.
also remove() method deletes all entries of item.
If you want to delete one item, you should call erase() method and pass an iterator to element you want to delete: lose.erase(p). Note that p will still be invalidated.
I would use multiset for card storage however.