是小邹啊

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

查找2.使用find_if查找 参数1起始位置迭代子 参数2截至为止迭代子  参数3()操作符重载

 查找3.find_end()查找 它是从右往左找 参数1起始位置迭代子 参数2截至为止迭代子  参数3需要查找的子集起始位置 参数4需要查找的子集截至为止 参数5比较函数 默认为==

class Find_lisi    //同时这个类要在学生类里声明为友元类
{
 public:
    bool operator ()(const Student &stu1)
    {
        if(stu1.name == "lisi")
            return true;
        else
            return false;
    }
};
    vector<Student>::iterator ist = vec_stu.begin();
    ist = find_if(ist,vec_stu.end(),Find_lisi());
      if(ist == vec_stu.end())
      cout<<"not found!"<<endl;
      else
          cout<<"found"<<endl;

//      while((ist = find_if(ist,vec_stu.end(),Find_lisi()))!=vec_stu.end())
//      {
//                    ist->showStu();
//                    ist++;
//
posted on 2020-04-27 14:00  是小邹啊  阅读(137)  评论(0编辑  收藏  举报