CJCoding With Joseph
15free / daySign inCreate account

Erase Every Matching Value

Write 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 — print one after the last line.

Hints4 available
Topics:
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.