I want to read a text word by word, avoiding any non-alphanumeric characters in a simple way.
After 'evolving' from text with white-spaces and '\n', I need to solve that problem in case there are also ',', '.' for example.
The first case was simply solved by using getline with delimiter ' '.
I wondered if there's a way to use getline
with multiple delimiters, or even with some kind of regular expression (for example '.'|' '|','|'\n'
).
As far as I know, getline
works in a way that it reads characters from the input stream, until either '\n' or delimiter
character reached. My first guess was that it is quite simple to provide it with multiple delimiters, but I found out that it's not.
Edit: just as a clarification. Any C style (strtok for example, which is for my opinion very ugly) or algorithmic type of solution is not what I'm looking for. It is fairly easy to come up with a simple algorithm to solve that problem, and implement it. I'm looking for a more elegant solution, or at least an explanation for why can't we handle it with the getline
function, since unless I completely misunderstood, should be able to somehow accept more than one delimiter.