I'm trying to find a string within in a vector of structs. But I keep getting an error, the error message is way too long so Ill upload it externally. A part of it is
"error: no match for 'operator==' (operand types are 'char' and 'const std::__cxx11::basic_string') { return *__it == _M_value; }"
The code Im currently using is:
struct constants {
std::string name, lastname;
float salary=0;
};
void searchPerson(const std::vector<constants> &search) {
using namespace std;
vector<constants>name;
string searchTerm;
cout << "Enter last name of the person you wish you lookup." << "\n";
cin >> searchTerm;
for (size_t k=0; k<name.size(); k++){
if (std::find(name[k].lastname.begin(), name[k].lastname.end(), searchTerm) != name[k].lastname.end())
{
cout << "Test" << "\n";
}
}
}
I just cant seem to get it working, I don't know whats wrong. The end goal is to let the user input the last name of a person, if theres a person with that last name stored in the program, it will print all the information about that person (first name, last name and salary). I will probably also be using the same search technique to delete a person from the program.
I can easily get it working by simply using a for loop, but there should definitely be a reason for using the find syntax, The below snippet work wonders.
for (size_t i=0; i<name.size(); i++) {
if (name[i].lastname== searchTerm)
cout << "Test" << "\n";
}