reverse函数功能是逆序(或反转),多用于字符串、数组、容器。头文件是#include
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;//反转字符串
cin>>s;
reverse(s.begin(), s.end());
cout<<s;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v = {
1,2,3,4,5};//反转容器
reverse(v.begin(), v.end());
vector<int>::iterator it;
for(it = v.begin(); it != v.end(); it++)
{
cout<<*it<<" ";
}
}