常用拷贝和替换算法replace_if
发布日期:2022-03-04 12:48:36 浏览次数:26 分类:技术文章

本文共 520 字,大约阅读时间需要 1 分钟。

黑马257

#include
#include
#include
#include
#include
#include
using namespace std;

class greater5

{
public:
bool operator()(int val)
{
return val>=5;
}
};
void myprint(int v)
{
cout << v << " ";
}
void test01()
{
vectorv1;
for (int i = 0; i < 10; i++)
{
v1.push_back(i);
}
cout << “替换前:” << endl;
for_each(v1.begin(), v1.end(), myprint);
cout << endl;
//将大于等于5替换成300
replace_if(v1.begin(), v1.end(), greater5(),300);
cout << “替换后:” << endl;
for_each(v1.begin(), v1.end(), myprint);
cout << endl;
}

int main()

{
test01();
}

转载地址:https://blog.csdn.net/qq_43752920/article/details/120560962 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:更改dataTable分页选择位置
下一篇:常用数据生成算法accumulate

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月23日 11时07分09秒