Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • do I need to add a prototype for this method in .h file ? Commented Dec 22, 2011 at 8:26
  • 12
    This is not exactly the "best" answer as it still uses a string literal which is the plain C constant character array. I believe the questioner was asking if he could tokenize a C++ string which is of type "string" introduced by the latter. Commented Apr 19, 2017 at 7:05
  • This needs a new answer because I strongly suspect the inclusion of regular expressions in C++11 has changed what the best answer would be. Commented Oct 25, 2017 at 15:45
  • 1
    To this answer have problem with strings that the first/last char is equal to the separator. e.g. the string " a" results is [" ", "a"].
    – y30
    Commented Nov 13, 2020 at 11:26
  • @y30: I think it results in ["","a"].
    – einpoklum
    Commented Nov 25, 2023 at 8:40