Use the reverse() function defined in the <algorithm> library.
void reverse (BidirectionalIterator first, BidirectionalIterator last);
Its function is to reverse the iterator in a range, so when acting on a string, the string can be reversed.
#include<algorithm>
#include<iostream>
#include<sting>
using namespace std;
int main(){
string orderstr = "hello world";
cout << "正序字符串:" << orderstr << endl;
reverse(orderstr.begin(), orderstr.end());
cout << "逆序字符串:" << orderstr << endl;
}
--------------------------------------------------
正序字符串:hello world
逆序字符串:dlrow olleh