C++: What Is The Difference Between Ostream And Ostringstream?
Answer : Put succinctly: ostringstream provides a streambuf , ostream requires the user to provide one. To understand the implications, it's necessary to understand a little how streams work, and I'm not sure that there's a good explanation of this on the Web. The basic abstraction of ostream is formatting textual output. You give it an int or a double (or a user defined type—more on that later), and it convert it into a stream of characters, of type char . What it does with that stream depends on the streambuf which is attached to it; this is an example of the strategy pattern, where streambuf is an abstract base class of the strategy[1]. The standard provides two implementations of streambuf , filebuf and stringbuf ; in practice, in all but the most trivial applications, you'll probably have some that you implement yourself. When outputting, you always use ostream ; it's the class over which the << operators are defined. You're form...