c++之字符或字符串逆序
C++ 字符逆序:#include#includeint main(){char s[101];cin>>s;reverse(s);cout}c++标准库有对容器进行逆序的操作,字符串本身就是字符的数组。可以直接使用C++标准类库函数reverse。#include#include#includeusing nam
·
C++ 字符逆序:
#include <iostream>
#include <string>
int main()
{
char s[101];
cin>>s;
reverse(s);
cout<<s<<endl;
}
c++标准库有对容器进行逆序的操作,字符串本身就是字符的数组。可以直接使用C++标准类库函数reverse。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;int main()
{ string str; //C++输入流完全支持string类型,没必要定义C的字符buffer。
cin>>str; //输入字符串
reverse(str.begin(), str.end()); //str执行完这句,就已经是逆序结果。
cout<<str<<endl; return 0;
}
更多推荐
已为社区贡献1条内容
所有评论(0)