Jan 26, 2017 at 1:11pm UTC
I have been looking for way to do this but I always end up with the library version to do or its only of a selected string not a getline input string am desperate to know even where to go with this :(
Last edited on Jan 26, 2017 at 11:00pm UTC
Jan 26, 2017 at 4:38pm UTC
OP: and if you want to define your own custom punctuation set:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <iostream>
#include <string>
#include <algorithm>
std::string remove_punct( const std::string& str );
int main()
{
std::string test = "\"This is a (some-what) punctuated string!?!.**@#$\"" ;
std::cout << remove_punct(test);
}
std::string remove_punct( const std::string& str )
{
std::string punctuations = {"*@#-$,;!.?\\\"'()" };//edit as required, note escape characters
std::string result{};
for (auto itr = str.cbegin(); itr != str.cend(); ++itr)
{
if (!std::any_of(punctuations.cbegin(), punctuations.cend(), [itr](char c){return c == *itr;}))
{
result += *itr;
}
}
return result;
}
Last edited on Jan 26, 2017 at 4:45pm UTC