LearnFrenzy
Sign in Take a free test

STL Algorithms and Iterators · STL Algorithms MCQ · Question 9

What is std::back_inserter for? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

Why write std::copy(a.begin(), a.end(), std::back_inserter(b))?

  • A To copy backwards
  • B So each copied element is appended with push_back, growing b as needed Correct
  • C To reverse a
  • D For speed only
Correct Answer: Option B

Copying to b.begin() of an empty b would write past its end.

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