反转string
# include <iostream>
# include <string>
# include <algorithm>
using namespace std;
int main()
{
string a;
cin >> a;
reverse(a.begin(), a.end());
cout << a;
return 0;
}
效果显示:
反转字符数组
# include <iostream>
# include <algorithm>
using namespace std;
int main()
{
char a[100];
cin.getline(a, sizeof(a));
int m = strlen(a);
reverse(a, a + m);
cout<<a;
return 0;
}
效果显示: