reverse()反转字符串的正确使用方式
生活随笔
收集整理的這篇文章主要介紹了
reverse()反转字符串的正确使用方式
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.reverse函數(shù)反轉string
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
? ? string N;
? ? cin>>N;
? ? reverse(N.begin(), N.end());
? ? cout<<N<<endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
2.reverse函數(shù)反轉字符數(shù)組
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
? ? char a[101];
? ? cin.getline(a,sizeof(a));
? ? int m=strlen(a);
? ? reverse(a,a+m);
? ? puts(a);
}
總結
以上是生活随笔為你收集整理的reverse()反转字符串的正确使用方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c/c++的输入输出总结
- 下一篇: context root修改无效:web