How do you reverse a string in place in C or C++?
Read Kernighan and Ritchie
#include <string.h>
void reverse(char s[])
{
int length = strlen(s) ;
int c, i, j;
for (i = 0, j = length - 1; i < j; i++, j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
#include <algorithm>
std::reverse(str.begin(), str.end());
This is the simplest way in C++.