1.使用string.h中的strrev函数
1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 char s[]="hello";
6 strrev(s);
7 puts(s);
8 return 0;
9 }
2.使用algorithm中的reverse函数
1 #include <iostream>
2 #include <string>
3 #include <algorithm>
4 using namespace std;
5 int main()
6 {
7 string s= "hello";
8 reverse(s.begin(),s.end());
9 cout<<s<<endl;
10 return 0;
11 }
这两个函数在我测试的时候出现了两种完全不同的情况
1.strrev函数只对字符数组有效,对string类型是无效的。
2.reverse函数是反转容器中的内容,对字符数组无效。
原文链接: https://www.cnblogs.com/wkfvawl/p/9053011.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/274159
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!