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