You can use seekg method to jump around within the istream.
If you open your file in binary mode, you can use tellg method to mark the position to jump to.
However, if you open your file in text mode, it is better to jump with offset instead (i.e. strm.seekg(offset, strm.cur)), due to how multibyte characters like newline are counted by tellg and seekg in text mode. So if you detect that the next character is going to be "p", then you can read the next n character, then jump back -n character if it's not what you're looking for.