Quote (postmortemvox @ Aug 16 2017 01:17am)
I see 3 issues:
1. Syntax of erase() call is broken:
http://www.cplusplus.com/reference/vector/vector/erase/I would suggest you use an iterater over the vector, which has the added benefit of making the erase() call more convenient since you'll already have the iterator parameter it's expecting:
https://stackoverflow.com/questions/4713131/removing-item-from-vector-while-iteratingIf you do, make sure you look at wilx's answer, which uses the return value of the erase() call to update the iterator. This also resolves the pesky issue of the remaining indexes being "shifted left" each time you delete an item in front of them.
2. The cout is being printed for each element that doesn't match "value". You'd be better off setting a flag true if-and-only-if a deletion is performed; if, at the end of the vector, the flag is still false, print the message.
3. Presumably, you want this function to modify a vector for later processing. If so, you'll want to pass the vector "by reference":
https://stackoverflow.com/questions/15890427/passing-vector-by-referenceThis will allow you to modify the vector passed in, rather than modifying a copy that is deleted as soon as the function returns.
Although I solved the problem, I am a man of my word as this was the solution x)
8/16/2017, 3:26:59 PM Sent -50.00 (4,350.01 -> 4,300.01) to postmortemvox (2,000.00 -> 2,050.00) C++ Vector Dilemma Answer
This post was edited by Cocoo on Aug 16 2017 01:27pm