Posted on 2008-05-11 11:47
山泉彎延 閱讀(4292)
評論(0) 編輯 收藏 引用
#include <functional>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
class out_times_x
{
private:
int multiplier;
public:
out_times_x(const int& k) : multiplier(k) { }
void operator()(const int& x) { cout << x * multiplier << " " << endl; }
};
int main ()
{
int sequence[5] = {1,2,3,4,5};
vector<int> v(sequence+0, sequence+5);
out_times_x f2(2);
for_each(v.begin(),v.end(),f2); // Apply function
system("pause");
return 0;
}