You can not. The only way std::stringstream knows that there isn’t any extra data is that there is no data in the stream.
This is an interesting thought, however. << on std::stringstream returns only true if the recording side was closed. The only problem with the idea is that std::stringstream has no idea about opening or closing.
The real question, however, is what are you trying to achieve. std::stringstream works in the process, and in this case there is really no need for formatting (this is an abstraction of iostreams in general). Just enter the source objects in std::deque . The only thing you will need to worry about formatting when you are communicating with the look. std::istringstream very useful, for example, when you get a string from std::getline in a file or from another source. Similarly, std::ostringstream is useful when formatting data for some external source, which requires a string of some sort. But I never found use for std::stringstream ; it is there apparently for reasons of orthogonality.
source share