1. 程式人生 > >reverse反轉函式

reverse反轉函式

使用algorithm中的reverse函式 

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string s= "hello";
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}

 

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    char s[]= "hello";
    reverse(s,s+5);
    cout<<s<<endl;
    return 0;
}