stl 中list 或者vector正确使用find查找类对象

来源:互联网 发布:十三水组合推荐算法 编辑:程序博客网 时间:2024/05/01 04:50

关键做好类对象的运算符重载

 

#include "stdafx.h"
#include <vector>
#include <algorithm>

class people
{
public:
 int age;
 char name[32];
public:
 bool operator == (const people&T)
 {
  if (age == T.age)
  {
   return true;
  }
  return false;
 }
};

typedef std::vector<people> myPeople;
typedef myPeople::iterator myPeopleIt;

int _tmain(int argc, _TCHAR* argv[])
{
 using namespace std;

 people m_p1;
 myPeople m_p;
 m_p.push_back(m_p1);
 myPeopleIt it = find(m_p.begin(),m_p.end(),m_p1);
 if (it != m_p.end())
 {
  printf("find it");
 }
 
 return 0;
}

原创粉丝点击