newplan

阿基米德在洗澡時發現浮力原理,高興得來不及穿㆖褲子,跑到街㆖大喊:Eureka(我找到了)。
posts - 39, comments - 26, trackbacks - 0, articles - 4
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

STL for_each简单实例

Posted on 2008-05-11 11:47 山泉弯延 阅读(4263) 评论(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;
}


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理