C++ vector 自定义类,重载==操作符,使用STL的find查找

#include 
#include 
#include 
#include 

using namespace std;

class onec
{
private:
    int i;
    char c;
    double d;
    QString str;
public:
    onec(int ix, char cx, double dx, QString sx) {i = ix; c = cx; d = dx; str = sx;}
    int showID(void) {return i;}
    bool operator == (const onec &x) {return (this->i == x.i)&&(this->c == x.c)&&(this->d == x.d)&&(this->str == x.str);}
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    cout<<"STL_TEST_FIND_CLASS"< o;
    for(int i=0; i<10; i++)
    {
        o.push_back(onec(i, 'c', i/10, "str"));
    }

    onec of(5, 'c', 5/10, "str");
    vector::iterator rst2 = find(o.begin(), o.end(), of);

    /**/
    if(rst2 == o.end())
        cout<<"no result"<showID()<

你可能感兴趣的:(C++ vector 自定义类,重载==操作符,使用STL的find查找)