C++ 字符串倒置

来源:互联网 发布:php app微信支付 编辑:程序博客网 时间:2024/06/07 10:56

字符串的倒置你可以想到很多方法,例如你:你可以用循环把一个字符串依次的倒置赋值给另外一个字符串然后输出,还有就是用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;}

0 0
原创粉丝点击