谓词 一元谓词
发布日期:2022-03-04 12:48:33 浏览次数:26 分类:技术文章

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

黑马238

#include
#include
#include
#include
#include
#include
using namespace std;
//一元谓词
class greaterFive
{
public:
bool operator()(int val)
{
return val > 5;
}

};

//函数对象在使用时,可以像普通函数那样调用,可以有参数,可以有返回值

void test01()

{
vectorv;
/for (vector::iterator it = v.begin(); it != v.end(); it++)/
for(int i=0;i<10;i++)
{
v.push_back(i);
}
//查找容器中 有没有大于5的数字
vector::iterator it=find_if(v.begin(), v.end(), greaterFive());
if (it == v.end())
{
cout << “can not find” << endl;
}
else
{
cout << “find it” << *it<<endl;
}
}
int main()
{
test01();
}

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

上一篇:STL函数对象基本使用
下一篇:谓词 二元谓词

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年03月29日 10时55分23秒