stl 中list 或者vector正确使用find查找类对象
2010-11-19 09:42
477 查看
关键做好类对象的运算符重载
#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;
}
#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;
}
相关文章推荐
- STL 查找vector容器中的指定对象:find()与find_if()算法
- STL 查找vector容器中的指定对象:find()与find_if()算法
- C++ vector 自定义类,重载==操作符,使用STL的find查找
- STL中的find,find_if函数(对类、容器(vector、list)进行查找)
- STL中Vector容器Find的使用(int查找)
- 对象的集合 -- 栈,使用stl 中的vector 或者 原始数组来实现
- 使用STL通用算法find_if()在list中搜索对象
- STL中vector的赋值,遍历,查找,删除,自定义排序——sort,push_back,find,erase
- STL中list,vector,deque,map,set区别、联系和使用场景
- (原創) 如何删除std::vector内的element?(使用find) (C/C++) (STL)
- STL中Vector容器Find的使用(泛型)
- STL中vector和list的使用
- STL之vector,数组线性容器array,list容器,算法find,find_if,bind1st,仿函数
- 关于在STL容器list中使用find_if 函数
- find_if和函数对象结合实现对自定义类型vector的查找
- C/C++--STL中list,vector,deque,map,set区别、联系和使用场景
- 【转】用find_if查找vector内对象的成员
- STL中的list和vector使用(一)更正
- STL中vector查找算法find()和find_if()深入比较
- stl中vector,list,deque的使用准则