I\'m a newbie programmer and I\'m working on a program that holds a registry of pets in a hotel (some silly exercise we saw in class, doesn\'t matter). I\'m using vectors for ho
A vector is an unsorted container so the simple solutions are really your only choice.
void RemovePet(std::vector<Pet> & pets, std::string name) {
pets.erase(
std::remove_if(pets.begin(), pets.end(), [&](Pet const & pet) {
return pet.Name == name;
}),
pets.end());
}
This is known as the Erase-remove idiom.
Note that this will remove all pets matching that name, not just one.