您好,欢迎来到九壹网。
搜索
您的当前位置:首页c++中字符串反转的3种方法

c++中字符串反转的3种方法

来源:九壹网
c++中字符串反转的3种⽅法

第⼀种:使⽤string.h中的strrev函数

#include #include using namespace std;int main(){

char s[]=\"hello\"; strrev(s); cout<第⼆种:使⽤algorithm中的reverse函数

#include #include #include using namespace std;int main(){

string s = \"hello\"; reverse(s.begin(),s.end()); cout<第三种:⾃⼰编写

#include using namespace std;void Reverse(char *s,int n){ for(int i=0,j=n-1;iint main(){

char s[]=\"hello\"; Reverse(s,5); cout<

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务