To remove set of chars from a given string, i have implemented this function.
void removeChars (string& str, const string& chars) { vector <bool> v (256, false); for (int i=0; i < chars.size(); ++i) { v[chars[i]] = true; } int k=0; for (int j=0; j < str.size(); ++j) { if (v[str[j]]==false) { str[k] = str[j]; ++k; } } str[k] = '\0'; } But after processing the string from this function. Its printing some garbage value.
string s1 = "trying to remove chars from string"; string s2 = "tr"; removeChars2 (s1, s2); Now print s1
ying o emove chas fom sing string Expected : ying o emove chas fom sing is there anything wrong in this implementation.
str.erase(k);at the end of the RemoveChars function.