You mean something like
string string_reverse( const string& s ) {
string ret;
copy( s.rbegin(), s.rend(), back_inserter( ret ) );
return ret;
}
If you want to avoid for loop or while loop then you have to use recursion
void str_reverse(char str[],int startIndex,int endIndex)
{
if(startIndex >= endIndex) return;
str_reverse(str,++startIndex,--endIndex);
str[startIndex-1]^=str[endIndex]^=str[startIndex-1]^=str[endIndex];
}
int main(int argc,char* argv[])
{
char str[] = "MyString";
str_reverse(str,0,strlen(str));
printf("%s\n",str);
return 0;
}