reverse function-reverse container content

The function of the reverse function is reverse order (or reverse), which is mostly used for strings, arrays, and containers. The header file is #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<<" ";
    }
}

Guess you like

Origin blog.csdn.net/weixin_51216553/article/details/110137285