码迷,mamicode.com
首页 > 其他好文 > 详细

transform函数

时间:2017-07-28 23:57:11      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:for   first   容器   一个   迭代器   com   ret   return   html   

摘自:http://blog.sina.com.cn/s/blog_8ec0965801012szd.html

transform(first,last,result,op);//first是容器的首迭代器,last为容器的末迭代器,result为存放结果的容器,op为要进行操作的一元函数对象或sturct、class。

transform(first1,last1,first2,result,binary_op);//first1是第一个容器的首迭代器,last1为第一个容器的末迭代器,first2为第二个容器的首迭代器,result为存放结果的容器,binary_op为要进行操作的二元函数对象或sturct、class。

op表示一些元素之间的一些操作,具体示例如下:

#include <iostream>
#include <algorithm>
using namespace std;
char op(char ch)
{
if(ch>=‘A‘&&ch<=‘Z‘)
return ch+32;
else
return ch;
}
int main()
{
string first,second;
cin>>first;
second.resize(first.size());
transform(first.begin(),first.end(),second.begin(),op);
cout<<second<<endl;
return 0;
}

transform函数

标签:for   first   容器   一个   迭代器   com   ret   return   html   

原文地址:http://www.cnblogs.com/qinguoyi/p/7252714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!