c++ 通过find在vector中查找自定义类

//by 鸟哥 通过find在vector中查找自定义类
//有疑问请留言或加群 1032082534
#include
#include
#include
using namespace std;
class Point3d{
    double x,y,z;
    public:
    Point3d(double x,double y,double z):x(x),y(y),z(z){}
    bool operator == (const Point3d &p) {
        return (this->x == p.x)&&(this->y == p.y)&&(this->z == p.z);
    }
};

int main(){
    
    vector<Point3d> p{{0,0,0},{1,2,3},{1.1,2.1,3.1},{10,11,11}};
    vector<Point3d>::iterator result = find(p.begin(), p.end(), Point3d(10,11,11)); 
    if (result == p.end())  
        cout << "没找到" << endl;
    else 
        cout << "找到" << endl;
}

运行结果:

找到

你可能感兴趣的:(c++)