编程语言
首页 > 编程语言> > 替换算法replace_if

替换算法replace_if

作者:互联网

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Print
{
public:
   void operator()(int i)
   {
      cout << i << endl;
   }
};

class Replace
{
public:
   bool operator()(int i)
   {
      return i >= 3;
   }
};

int main()
{
   vector<int> v;
   for(int i = 0; i < 5; i++)
   {
      v.push_back(i);
   }

   replace_if(v.begin(), v.end(), Replace(), 30);
   for_each(v.begin(), v.end(), Print());
   
   return 0;
}
$ ./a.out           
0
1
2
30
30

标签:end,int,30,replace,Print,include,替换算法
来源: https://www.cnblogs.com/zhangxuechao/p/16537386.html