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?
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.