zoukankan      html  css  js  c++  java
  • 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.自己编写函数:对于字符串的两边进行交换。

     

  • 相关阅读:
    开发日记1
    探索需求2
    探索需求1
    周总结8
    周总结7
    周总结6
    周总结5
    周总结4
    周总结3
    周总结2
  • 原文地址:https://www.cnblogs.com/suppercobweb/p/6808462.html
Copyright © 2011-2022 走看看