Given the input: const char input[] = "lorem\t, ipsum"
and the expected outputs: char first[size(input)]
and second[size(input)]
I can do this:
sscanf(input, "%s , %s", first, second);
Ignoring white-space and the delimiting character with ,
. I'd like to do the same thing with a stream, but the best I can come up with is:
istringstream foo(input);
foo >> first;
foo.ignore(numeric_limits<streamsize>::max(), ',');
foo >> second;
What I'm really looking for is something more like:
istringstream(input) >> first >> ',' >> second;
But obviously that's illegal. I've thought of:
- A dummy value to extract the delimiter into
- A regex iterator
I don't know if there's a more elegant solution, I'd certainly like something that I could do inline, similar to the sscanf
solution.