The difference between Sstream and Strstream in C + + standard library detailed analysis _c language

Source: Internet
Author: User

There are two types of string flows in C + +, one defined in Sstream and the other defined in Strstream. What they achieve is basically the same thing.

Strstream contains
Class Strstreambuf;
Class Istrstream;
Class Ostrstream;
Class Strstream;
They are written based on the C type string char*

Included in the Sstream
Class Istringstream;
Class Ostringstream;
Class Stringbuf;
Class StringStream;
Class .....
They're written based on std::string.

So Ostrstream::str () returns a string of char* types
and Ostringstream::str () returns a string of std::string types

Note the difference between the two when you use it, and generally recommend using the std::string type of string
Of course, if you want to maintain compatibility with C, it's also a good choice to use Strstream.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.