STL中Vector容器Find的使用(泛型)

来源:互联网 发布:淘宝上那些解id可信吗 编辑:程序博客网 时间:2024/05/13 03:33
#include <list>#include <algorithm>#include <iostream>using namespace std;class CTest{public:CTest(int x, int y) { this->x = x; this->y = y; };~CTest() { };bool operator == (const CTest &other);public:int x;int y;};bool CTest::operator == (const CTest &other){if(this->x == other.x && this->y == other.y)return true;elsereturn false;}int main(){list < CTest > Test;list < CTest > :: iterator iter;Test.push_back(CTest(10, 20));Test.push_back(CTest(30, 40));Test.push_back(CTest(50, 60));iter = find(Test.begin(), Test.end(), CTest(30, 40));if(iter != Test.end())cout << iter->x << "\t" << iter->y << endl;elsecout << "Can't find it!" << endl;    return 0;}


0 0
原创粉丝点击