Apr 8, 2018 at 7:57am UTC
Write your question here.
i defined the first function to find matches but i need to change it into the second function provided. it will search through a vector and return a vector of pointers to the vector of objects that match the search input. i am having trouble defining the second function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
void AddressBook::match(std::string namesearch)
{
for (std::vector<Person>::const_iterator itr = perV.begin(); itr < perV.end(); ++itr)
{
if (strstr(itr->firstName.c_str(), namesearch.c_str()) ||
strstr(itr->lastName.c_str(), namesearch.c_str()))
{
std::cout << itr->firstName << ' ' << itr->lastName
<< std::endl << "Email: " << itr->email << std::endl;
}
}
}
std::vector<const Person*> AddressBook::matches(std::string prefix) const
{
{
}
return std::vector<const Person*>();
}
Last edited on Apr 8, 2018 at 8:17am UTC
Apr 9, 2018 at 5:11am UTC
std::vector<const Person*> AddressBook::matches(std::string prefix) const
{
std::vector<const Person*> ptrV;
for (auto iter = perV.begin(); iter < perV.end(); ++iter)
{
if (strstr(iter->firstName.c_str(), prefix.c_str()) ||
strstr(iter->lastName.c_str(), prefix.c_str()))
{
auto ptr = &(*iter);
ptrV.push_back(ptr);
}
return ptrV;
}
}
will this work