C++STL算法篇reverse反转函数

reverse的作用:

答:将区间[iterator1,iterator2)内的元素反转。使用时包含algorithm头文件,打开std命名空间。

int main()
{
	string a = "hello world!";
	reverse(a.begin(),a.end());//!dlrow olleh
	cout << a;
   
    string b="hello world!";
    reverse(a.begin(),a.begin()+5); //olleh world!
    cout<<b;
}
原创文章 23 获赞 1 访问量 364

猜你喜欢

转载自blog.csdn.net/weixin_44806268/article/details/105633938
今日推荐