← Back to STL Containers
Question 561
Erase Every Matching Value
Erase Every Matching Value
Write a functionvoid removeValue(vector<int>& v, int x)that removes every element equal toxfromv, keeping the other elements in their original order. Use a single iterator loop that callsv.erase(it)for each match; do not useremove/remove_if. The test prints the remaining elements separated by spaces on one line. For {1, 2, 3, 2} withx = 2the output line is1 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
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.