在vector里存储特殊的结构题,并且支持find函数查找

来源:互联网 发布:落英纷飞 音乐软件 编辑:程序博客网 时间:2024/06/05 19:00

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;

}

阅读全文
0 0
原创粉丝点击