3

std::ostream's have a flush() method which:

Writes uncommitted changes to the underlying output sequence.

What does that mean for an std::stringstream? If I understand correctly, it means there's nothing to be done for such a stream. Is this true?

einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

5

flush() triggers a call of the stream's rdbuf member's pubsync() method (which in turns calls sync() ). For string streams, the rdbuf is a std::basic_stringbuf, and as the link indicates, its pubsync()/sync() behavior is to do nothing.

Thus, indeed, your assumption is valid: std::stringstream::flush() does nothing.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Indeed, maybe interesting to mention that this method exists to ensure that you can use any kind of stream without knowing it's implementation – JVApen Dec 28 '19 at 18:59
  • @JVApen: I think people know about being able to `<< std::flush` to every ostream; but fair enough. – einpoklum Dec 28 '19 at 19:24