在vector里存储特殊的结构题,并且支持find函数查找
#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;
struct st {
int a;
int b;
st(int _a = 0, int _b = 0) : a(_a), b(_b) {}
};
bool operator == (const st& left, const st& rigt)
{
return left.a == rigt.a && left.b == rigt.b;
}
int main()
{
vector<st> vst;
vst.push_back(st(0, 1));
vst.push_back(st(0, 2));
vst.push_back(st(1, 2));
vst.push_back(st(5, 1));
vst.push_back(st(5, 5));
st t = st(5, 1);
vector<st>::iterator ifind = find(vst.begin(), vst.end(), t);
if (ifind != vst.end())
{
cout<<"finded"<<endl;
}
return 0;
}