27. Splitting a string into tokens with a list of possible delimiters

Two different versions of a splitting function are listed as follows:

  • The first one uses a single character as the delimiter. To split the input string it uses a string stream initialized with the content of the input string, using std::getline() to read chunks from it until the next delimiter or an end-of-line character is encountered.
  • The second one uses a list of possible character delimiters, specified in an std::string. It uses std:string::find_first_of() to locate the first position of any of the delimiter characters, starting from a given position. It does so in a loop until the entire input string is being processed. The extracted substrings are added to the result ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.