What should I use instead of std::ostrstream?

c++, deprecated, stream

Solution

You could use `std::ostringstream`. Similarly, instead of `std::istrstream` you should use `std::istringstream`. You need to include the `<sstream>` header for these classes.

You could also see this question which explains why `strstream` was deprecated.

Problem

I like to use `std::ostrstream` to format text but not print it to stdout but instead write it into an `std::string` (by accessing the `std::ostrstream::str()` member). Apparently this is deprecated now. So, how am I supposed to write formatted objects to a string, with the same convenience as when writing to a stream?

Original source

Related problems