1.使用string.h中的strrev函数
strrev(数组名);即可实现字符串的反转,2.使用algorithm中的reverse函数
#include<stdio.h>
#include<string.h>
int main()
{
char s[]="hello";
strrev(s);
puts(s);
return 0;
}
2.使用algorithm中的reverse函数
#include <algorithm>
using namespace std;
int main()
{
string s= "hello";
reverse(s.begin(),s.end());
cout<<s<<endl;
return 0;
}
这两个函数在我测试的时候出现了两种完全不同的情况
1.strrev函数只对字符数组有效,对string类型是无效的。
2.reverse函数是反转容器中的内容,对字符数组无效。
转载:
https://blog.youkuaiyun.com/weixin_27848283/article/details/90524674