Ruth
-1
Q:

remove character from string on condition c++

class IsChars
{
public:
    IsChars(const char* charsToRemove) : chars(charsToRemove) {};

    bool operator()(char c)
    {
        for(const char* testChar = chars; *testChar != 0; ++testChar)
        {
            if(*testChar == c) { return true; }
        }
        return false;
    }

private:
    const char* chars;
};
auto chars_to_remove = "()- ";
str.erase(std::remove_if(str.begin(), str.end(), IsChars(chars_to_remove)), str.end());
0

New to Communities?

Join the community