LearnFrenzy
Sign in Take a free test

std::string · std::string MCQ · Question 20

How to reverse a std::string Answer, explanation & discussion

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

Which call reverses s in place?

  • A s.reverse();
  • B std::reverse(s.begin(), s.end()); Correct
  • C s = -s;
  • D std::reverse(s);
Correct Answer: Option B

std::string has no reverse member, but all <algorithm> functions work on its iterators. C++20 also offers std::ranges::reverse(s).

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