您的位置:首页 > 编程语言 > C语言/C++

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: