C++ 仿函数VECTOR中查找
2016-06-11 13:16
260 查看
class findx //仿函数 用来查找容器中元素
{
public:
findx(const int Y,int M, int D){Year=Y;Month=M;Day=D;}
bool operator()(STRING& t) //重载()
{
if(t.year == Year && t.month == Month && t.day == Day)
return true;
else
return false;
}
public:
int Year;
int Month;
int Day;
};
查找:
vector<STRING>::iterator it = find_if( information.begin( ), information.end( ), findx(y,m,d) );
//迭代器
if(it!=information.end())
{
it->Congradu();
}
else
{
cout<<"NO"<<endl;
}
{
public:
findx(const int Y,int M, int D){Year=Y;Month=M;Day=D;}
bool operator()(STRING& t) //重载()
{
if(t.year == Year && t.month == Month && t.day == Day)
return true;
else
return false;
}
public:
int Year;
int Month;
int Day;
};
查找:
vector<STRING>::iterator it = find_if( information.begin( ), information.end( ), findx(y,m,d) );
//迭代器
if(it!=information.end())
{
it->Congradu();
}
else
{
cout<<"NO"<<endl;
}
相关文章推荐
- 引用与const
- C/C++杂记 虚函数的实现的基本原理(图文)
- C++ c++与C语言的区别(三目运算符,const修饰符)
- C++成员函数的存储方式
- HDOJ 2024 C语言合法标识符
- Geekband C++面向对象高级编程(下) 第二周笔记 暗影行者
- C语言多线程,动态库和静态库
- C++ c++与C语言的区别(struct类型的加强,函数-变量类型加强,bool类型)
- 浅析C++继承与派生
- 1.7 C++语句
- 1.4 C++的数据类型
- 1.3 C++的词法单位
- 1.2 简单的C++程序实例
- 1.1 C++语言概述
- C++ c++与C语言的区别(实用性增强,register关键字增强,全局变量检测增强)
- 关于c++中的const
- typedef的一些用法
- 十年之后重学C语言
- C++作业7
- 最近学习的内容