Question 14
Back to Exercise
What does v.erase(std::remove(v.begin(), v.end(), 0), v.end()); do?
- A Removes only the first 0
- B Removes every 0 from v Correct
- C Removes the last element
- D Clears the vector
Correct Answer: Option B
std::remove moves the kept elements forward and returns the new end; erase cuts off the rest. C++20: std::erase(v, 0).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!