I need to split a string into a fields. The string is delimitted into fields with a comma (,). Do I have to extract each field via string operations like finding position to next delimitter and extracting appropriate substring or can I do it via something more elegant - I think recall seeing some mechanism where the string is split into a vector directly.
You could use getline, but the elegant solution you're looking for is a split function.
boost has one (boost::algorithm::split), although it's awkward to use.
You can use a wrapper for the common case, something along the lines of:
Thanks for the responses - I will probably resort to writing my own and may then very well use strtok under the the hood for it. I'm reluctant to include boost into my project at this stage.
It would have been nice to have the boost type of solution in stl.