I want it to consider anything that isn't an alphabet character to be a delimiter. How can I do this?
You can't. The default delimiter is \n:
while (std::getline (std::cin, str) // '\n' is implicit
For other delimiters, pass them:
while (std::getline (std::cin, str, ' ') // splits at a single whitespace
However, the delimiter is of type char, thus you can only use one "split-character", but not what not to match.
If your input already happens to be inside a container like std::string, you can use find_first_not_of or find_last_not_of.
In your other question, are you sure you have considered all answers? One uses istream::operator>>(std::istream&, <string>), which will match a sequence of non-whitespace characters.
You don't. getline is a simple tool for a simple job. If you need something more complex, then you need to use a more complex tool, like RegEx's or something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With