①CIN>>: Unable to receive the space, tap key and the space, tap key, carriage return delimiter;
②cin.get (): Can receive a space, tap key and a carriage return as a terminator;
One: You can enter a single character
Format:
Char ch;
Ch=cin.get ();/cin.get (CH);
Two: Can input string
Format:
Cin.get (character array name, number of elements)
③getline (): Can receive a space, tap key and a carriage return as a terminator;
Format:
String str;//strings Variable
Getline (CIN,STR);
④cin.getline (): Can receive space, Tapa key and end with carriage return;
Format: cin.getline (character array name, number of elements)
Char m[20];
Cin.getline (m,20);
③ and ④ are similar, the singular getline () belongs to the string stream class, and Cin.getline () belongs to the IStream stream class, which is a different function.
5, the input of a blank line (that is, direct return) processing
Get (str,size): str will get ' \ n ' and set the CIN effect bit, close the input, but the carriage return remains in the input buffer, so if we reset cin with clear (), its next read input operation will capture ' \ nthe ';
Getline (str,size): str will get ' \ \ ' and will ' \ n ' remove, pail the actual bit, do not close the input. Therefore, for Cin.getline, a blank line is a valid input and does not affect the following input processing.
Gets () and GetChar () in the C language
①gets (character array name) is used to receive a string, which can include spaces, tap keys, and end with a carriage return;
②getchar (character variable name) is used to receive a single word upper ends with a carriage return, typically requiring two. the previous receive character, followed by a carriage return.
③putchar (character variable name or integer constant)
Differences between CIN, Cin.get (), Cin.getline (), Cin.getchar () in C + +