www.pudn.com > For_each.rar > For_each.cpp


#include  
#include   
#include  
#include  
 
using namespace std; 
//template   
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  v(sequence, sequence+5); 
 
 
	out_times_x f2(3); 
 
	for_each(v.begin(),v.end(),f2);   // Apply function 
 
	system("pause"); 
 
 
	return 0; 
}