How do you reverse a string in place in C or C++?

uvote picture uvote · Oct 13, 2008 · Viewed 318.6k times · Source

How do you reverse a string in C or C++ without requiring a separate buffer to hold the reversed string?

Answer

Greg Rogers picture Greg Rogers · Oct 13, 2008
#include <algorithm>
std::reverse(str.begin(), str.end());

This is the simplest way in C++.