LearnFrenzy
Sign in Take a free test

Arrays and Vectors · Arrays and Vectors MCQ · Question 14

What does the erase-remove idiom do? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links