#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
class Person{
public:
Person(){};
Person(string name, int id):m_name(name), m_id(id){}
string get_name()
{
return m_name;
}
int get_id() const
{
return m_id;
}
//const 对象的话需要调用常函数,否则会报cannot convert 'this' pointer from 'const class Person' to 'class Person &'
bool operator==(const Person &p)
{
return this->m_id == p.get_id();
}
private:
string m_name;
int m_id;
};
int main()
{
Person p1("zhangsan", 2);
Person p2("lisi", 5);
Person p3("wangwu", 7);
Person p4("zhaoliu", 3);
vector<Person> vec;
vec.push_back(p1);
vec.push_back(p2);
vec.push_back(p3);
vec.push_back(p4);
vector<Person>::iterator it;
it = find(vec.begin(), vec.end(), p2);
if (it != vec.end())
{
cout<<"find"<<endl;
}
return 0;
}
STL find
最新推荐文章于 2024-09-02 23:26:01 发布
500

被折叠的 条评论
为什么被折叠?



