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.自己编写函数:对于字符串的两边进行交换。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM