class person
{
public:
person(string name, int age)
{
this->mname = name;
this->mage = age;
}
public:
string mname;
int mage;
};
class greater20
{
public:
bool operator()(person& p)
{
return p.mage > 10;
}
};
void test02()
{
vector<person> v;
person p1("aaa", 10);
person p2("bbb", 20);
person p3("ccc", 30);
person p4("ddd", 40);
person p5("eee", 50);
v.push_back(p1);
v.push_back(p2);
v.push_back(p3);
v.push_back(p4);
v.push_back(p5);
vector<person>::iterator it = find_if(v.begin(), v.end(), greater20());
if (it == v.end())
{
cout << "没有找到" << endl;
}
else
{
cout << "找到了" << endl;
cout << "姓名:" << it->mname << "年龄: " << it->mage << endl;
}
}
找出大于10岁的,找出bbb后系统就break,但后面的三个人怎么显示出来呢
C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html
C和C++算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html