std::stringstream uses a
std::stringbuf as its stream buffer. A
std::stringbuf is seekable, like an ordinary file.
You can iterate through the buffered string to your heart's desire, then seek back to the beginning of the buffer, or to some other spot inside the string, and rewind the clock back where it was.