<c++ Learning one > About C + + input and output streams

Source: Internet
Author: User

Essence: bytes are extracted by byte stream at input and output

cin input stream, encountered blank, tabulation, etc., the input will stop.

Key to grasp the function:

(1) cin.get (); Reads a character from the stream

(2) cin.get (char ch); Usage is similar to (1)

(3) Cin.get (arryname,arsize); Read Arsize characters from the stream and deposit into Arryname

(4) cin.get (Arryname,arsize,char ch);//read arsize characters from the stream and deposit in Arryname, encountered CH stop

(5) Cin.getline (arryname,arsize);//Same (3)

(6) Cin.peek ()//pointer rest position, observe current character in stream, return type int

(7) cin.ignore (int num)//omit num characters from a stream

Test code:


1#include <iostream>2 using namespacestd;3 4 intMain () {5     CharC1;6     Charstr1[ One] = {0 };7     Charstr2[ One] = {0 };8     Charstr3[ -] = {0 };9 Ten     //(1) How to use the input stream Onecout <<"Please enter a string of stream characters:"; AC1 = cin.Get(); -cout <<"Output C1:"<< C1 <<Endl; -  theCin.putback (C1);//put C1 into the first character of the input stream -  -     //(6) How to use the input stream -     if(Cin.peek () = = (int) C1) cout <<"Cin.peek () put the characters in the first position"<<Endl; +     Elsecout <<"Cin.peek () the characters put in are not in the first position"<<Endl; -  +     //(3) How to use the input stream ACin.Get(STR1, One); atcout <<"output current Top 10 characters:"<< str1 <<Endl; -  -     //(7) How to use the input stream in (4) -Cin.ignore (5); -Cin.Get(STR2, One, EOF); -cout <<"the first 10 characters after the output is ignored:"<< str2 <<Endl; in  -     //(5) How to use the input stream in toCin.getline (STR3, -); +cout <<"the remaining string:"<< STR3 <<Endl; -  theSystem"Pause"); *     return 0; $}

Test results:

<c++ Learning one > About C + + input and output streams

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.