关于C++标准库 find函数的用法 一点问题

来源:百度知道 编辑:UC知道 时间:2024/04/30 08:08:04
find (迭代器 , 迭代器 , 查找内容) 这是函数原型
我现在定义这么一个类class Test
{
public :
Test (int a = 1 , char b = 'k') : a(a) , b(b) {};
int a;
char b;

};

然后我定义两个对象 存到list容器中
list<Test> n ;
Test t1 , t2 (3 , 'm') ;
n.push_front ( t1);
n.push_front ( t2 );

list<Test>::iterator p1 = n.begin() , p2 = n.end () ;

请问能否调用find函数 针对Time类中 int a 这个数据成员进行查找

如果能 请告诉我应该怎么写
万分感谢

楼上写的肯定不对

只能先遍历一遍容器,找到a值为所需要值的类,然后将这个类作为查找对象

iterator it = find(n.begin(),n.end(),a);
if(it == n.end()) cout<<"Not find"<<endl;
else{}