C++类属性transform

类属行transform的作用是,将某个函数作用到某一个区间内的每一个元素上,并将该函数所返回的结构保存到另一个区间中。

 
  
1 #include < algorithm >
2 #include < iostream >
3 #include < iterator >
4   using namespace std;
5
6   int sum( int val1, int val2) { return val1 + val2;}
7
8   int main()
9 {
10 cout << " Illustrating the generic transform algorithm. " << endl;
11 int array1[ 5 ] = { 0 , 1 , 2 , 3 , 4 };
12 int array2[ 5 ] = { 6 , 7 , 8 , 9 , 10 };
13 ostream_iterator < int > out (cout, " " );
14
15 transform( & array1[ 0 ], & array1[ 5 ], & array2[ 0 ], out ,sum);
16 cout << endl;
17 return 0 ;
18 }

显示结果为:

Illustrating the generic transform algorithm.
6 8 10 12 14

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值