一、reverse函数用法:
①、reverse函数头文件: #include<algorithm> 。
②、reverse函数第二个参数为末元素的下一个地址。
1.reverse函数反转string
#include <iostream>
#include <algorithm>
//#include <cstring>
using namespace std;
int main() {
string str;
cin>>str;
reverse(str.begin(), str.end());
cout<<str<<endl;
return 0;
}
结果:
2、reverse函数反转数组:
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int num[]={1,2,3,4,5,6};
re