问题及描述;
/*
02. *Copyright (c) 2016,烟台大学计算机学院
03. *All rights reserved.
04. *文件名称;test.cpp
05. *作者;邱凯
06. *完成日期;2016年6月8号
07. *版本号;v6.0
08. *问题描述; 阅读程序,体会用法(4)
09. *输入描述; 输入答案
10. *输出描述; 输出答案
11.*/
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
class myAdd: public binary_function<int,int,int>
{
public:
int operator()(int a, int b) const
{
return a+b;
}
};
int main()
{
int a[5]= {1,2,3,4,5};
vector<int> my(5);
transform(a,a+5,my.begin(), bind2nd(myAdd(), 4));
copy(my.begin(), my.end(), ostream_iterator<int>(cout, " "));
cout<<endl;
transform(a,a+5,a,my.begin(), myAdd());
copy(my.begin(), my.end(), ostream_iterator<int>(cout, " "));
cout<<endl;
return 0;
}
运行结果;