In C++ std::ostream is the base class for output streams.
Output stream class to operate on strings.
In c++ you could associate the output stream with a null device too and test the number of charactes printed with std ostream tellp;however using ostringstream is a way better solution see the answers by devsolar or angew
Using sprintf with std::string in C++
Ostream is more general subclasses support writing to different places ostringstream is a specific one writing to a string
C++: What is the difference between ostream and ostringstream?