I am trying to find if there is better way to check if the string has special characters. In my case, anything other than alphanumeric and a \'_\' is considered a special charac
Using
s.erase(std::remove_if(s.begin(), s.end(), my_predicate), s.end()); bool my_predicate(char c) { return !(isalpha(c) || c=='_'); }
will get you a clean string s.
s
Erase will strip it off all the special characters and is highly customisable with the my_predicate function.
my_predicate