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!