Parsing null terminated strings from a stream

During a project this week, my project partner and I ran into a problem that is somewhat interesting: how do you parse a string whose delimiters are null characters (‘\0’)? For example, how do you separate something like this:

This\0is\0a\0null\0character\0separated\0string

…into something like this:

This
is
a
null
character
separated
string

The problem is, of course, that you can’t put this into a std::string and iterate over the string to separate it out, because std::string terminates on the null character. So doing something like this:

…results in str returning only "This" when it is used, and iterating would stop at the first null character.

So what can we do? Assuming our null terminated string is of type char *, we can actually use this string constructor behavior to our advantage by pointing at the beginning of each part of the string, then moving forward past the null terminator until we’ve reached the end of our character stream.