Erasing a string

I have a function set to erase certain characters from a string...

1
2
3
4
5
6
7
8
  
string Filter (string clean)
{
    clean.erase(remove(clean.begin(), clean.end(), ' '), clean.end());
    clean.erase(remove(clean.begin(), clean.end(), ispunct), clean.end());
    return clean;
}
    


But, only the erase ' ' works. Do I have the other one wrong?
There are two versions of ispunct, one in <cctype> and one in <locale>, so if both of them has been declared the compiler will be confused and don't know which one to pick. The best way to avoid this sort of problem is to wrap it in a lambda.

 
clean.erase(remove_if(clean.begin(), clean.end(), [](char c){ return ispunct(c); }), clean.end());
Last edited on
Topic archived. No new replies allowed.