Both thec++20 provides us with split_view
to tokenize strings, in a non-destructive manner: https://topanswers.xyz/cplusplus?q=749#a874
The previous methods cannot generate a tokenized vector
in-place, meaning without abstracting them into a helper function they cannot initialize const vector<string> tokens
. That functionality and the ability to accept any white-space delimiter can be harnessed using an istream_iterator
. For example given: const string str{ "The quick \tbrown \nfox" }
we can do this: