string stream;

Source: Internet
Author: User

The string stream is defined in the header file <sstream>;

Can be like the standard input and output stream, automatic discriminant data type output, encountered a space to stop;

Definition: StringStream SS;//defines a string stream that can be input or output;

ss<< "Carea M 65.3"; Initialize the data inside the stream,
String name;
int age;
char sex;
float weight;
ss>>name>>age>>sex>>weight; Output the data in the stream to the variable;
cout<< "Name:" <<name<<endl
<< "Age:" <<age<<endl
<< "Gender:" <<sex<<endl
<< "Weight:" <<weight<<endl;

********************************

You can also define an input stream individually (in fact, an output stream, which outputs data from a string string to a variable in a different data type;)

String s= "Hello world!";

String A;

Istringstream sin (s); Using S to initialize the input stream, the current content in S is present in the stream;

sin>>a;//Output "Hello" to A;

That's it.

string stream;

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.