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

 

相关文章:

  • 2022-02-19
  • 2022-12-23
  • 2021-05-16
  • 2021-09-16
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
相关资源
相似解决方案