Erase Every Matching Value
mediumQuestion 561Write a function void removeValue(vector<int>& v, int x) that removes every element equal to x from v, keeping the other elements in their original order. Use a single iterator loop that calls v.erase(it) for each match; do not use remove/remove_if.
The test prints the remaining elements separated by spaces on one line. For {1, 2, 3, 2} with x = 2 the output line is 1 3.
Do NOT write a main function.
Expected output
1 3 3
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL ContainersIterators
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.