I have a vector personInfo that contains class objects of person details
vector<person> personInfo;
I am trying to use std::find to search for a existing name in the vector.
I overloaded my == operator.
person.h
class person {
public:
std::string name;
friend bool operator==(const person &lhs, const person &rhs);
};
bool operator==(const person &lhs, const person &rhs) {
return lhs.name == rhs.name;
main.cpp
#include "person.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int main {
//assuming that I have added stuff into the vector already.
std::cout << " " << std::endl;
std::cout << "Enter name to find: ";
std::cin >> name;
std::vector<person>::iterator it;
it = std::find(personInfo.begin(),personInfo.end(),person(name,false));
if(it !=personInfo.end()) {
cout << "found!" << endl;
}
}
the program compiles successfully but nothing happens even if I enter a existing name that is inside the vector.
I not sure if anything I wrote is wrong. please help. thanks