c++中字符串的反转

1.对于用char定义的字符串:使用string.h中的strrev函数

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    char s[]="123456";//不能是string类型;
    strrev(s);
    cout<<s<<endl;
    return 0;
}

2.对于string类型的:使用algorithm中的reverse函数

#include<iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    string s[]="123456";
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}

3.自己编写函数:对于字符串的两边进行交换。

 

posted on 2017-05-04 17:50  cobweb  阅读(27120)  评论(0编辑  收藏  举报

导航