字符串的倒置你可以想到很多方法,例如你:你可以用循环把一个字符串依次的倒置赋值给另外一个字符串然后输出,还有就是用string 里面的reverse()函数。
加入头文件:
#include <string>
#include <algorithm>
例子:#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string str1;
cin>>str1;
cout<<"原始字符串是:"<<str1<<endl;
reverse(str1.begin(),str1.end());
cout<<"转换后的字符串是:"<<str1<<endl;
return 0;
}