編程第六十九天

c++ STL標準函數find進行vector 、list鏈表查找

#include <vector>
#include <algorithm>
#include <iostream>

class example
{
public:
example(int val)
{
i = val;
}

bool operator==(example const & rhs)
{
return (i == rhs.i) ? true : false;
}

private:
int i;
};
using namespace std;
int main(void)
{
vector<example> ve;
ve.push_back(1);
vector<example>::iterator it;
example elem(1);
it = find(ve.begin(), ve.end(), elem);
cout<<boolalpha<<(*it == elem);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章