C + + StringStream

Source: Internet
Author: User

C + + introduces the three classes of Ostringstream, Istringstream, StringStream, which are included in the sstream.h header file. In three classes

1) The Istringstream class is used to perform input operations of C + + style streaming;

2) The Ostringstream class is used to perform C-style streaming output operations;

3) The Strstream class can support both styles of streaming input and output operations.

First, StringStream

One of the important functions of stringstream is to make the conversion of data, which is more safe and convenient than other implementations.

1) The value turns into a string:

     

In the code we first declare an integer n using the scientific notation, then declare a Stringsteam instance STRM, then the integer n "flows" into the STRM, and then let the STRM data "out" into S, the successful completion of the conversion, the results of the operation are as follows:

2) string into numeric value:

In the code we first declare a string class S, let it flow into the STRM and then stream to N, and then successfully turn S into double:

However, if we declare the type of n as int, the conversion is still successful, except that the value of n will be 1 because n is not int, so the decimal conversion will end when "Inflow" N from STRM.

To IS continued.

C + + StringStream

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.