类属行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

相关文章:

  • 2021-05-25
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-20
  • 2018-03-19
  • 2021-11-03
  • 2021-07-19
  • 2021-08-14
相关资源
相似解决方案