The differences between sstream and strstream in the C++ standard library are explained in detail

  • 2020-04-02 01:32:22
  • OfStack

There are two types of string streams in C++, one defined in sstream and one defined in strstream. They implement basically the same thing.

Strstream contains
The class strstreambuf;
The class istrstream;
The class ostrstream;
The class strstream;
They are written based on the C type string char*

Sstream contained in the
The class istringstream;
The class ostringstream;
The class stringbuf;
The class stringstream;
The class... .
They are written based on STD ::string

So ostrstream:: STR () returns a string of type char*
Ostringstream :: STR () returns a string of type STD ::string

Be aware of the difference when using them, and it is generally recommended to use strings of type STD ::string
Of course, strstream is also a good choice if you want to stay compatible with C


Related articles: