replace() replaces the part of the string at the given position and size once. you need a loop:
1 2 3 4 5 6 7 8
std::string::size_type found; // EDIT: I knew there was an typo...
do
{
found = a[i].find(str);
if(found != std::string::npos)
a[i].erase(found, str.size()); // I this case erase suffice
}
while(found != std::string::npos);
Yes. find() returns and invalid number(-1) if it doesn't find the requested string and replace() complains about that invalid value. Therefore I introduced if(found != std::string::npos) // npos is an invalid value