1. Cin, Cin. Get, Cin. Getline
When CIN reads data, it ends with a space. When the space character is discarded, the input carriage return is complete, which is normal.
Cin. Get is used to read characters. The input carriage return ends, but the carriage return and space characters are not discarded.
Note: cin. get () and CIN. get (char) is equivalent, but cin. get (char *, INT) is used to read strings. It can accept space characters. When the carriage return ends, the character is read according to the specified length (length minus 1), and the last carriage return is discarded.
Cin. getline () and CIN. get (char *, INT) has the same usage. The only difference is cin. when the string input by get (char *, INT) is too long, it will not cause the CIN function error, and subsequent CIN operations will continue to be executed. However, the former will cause the CIN function error, and subsequent CIN operations will not be executed.
2. scanf, getchar read characters
Scanf ("% C", & Ch)
Ch = getchar ()
The two are the same. They can be read based on the number of variables using space characters and carriage return characters.
3. scanf, gets read string
Scanf ("% s", STR) encounters a space character and a carriage return character. A space character and a carriage return character cannot be entered.
Gets (STR) stops when a carriage return ends, but spaces are allowed in the string. Do not discard the space character.
1. Cin, Cin. Get, Cin. Getline
When CIN reads data, it ends with a space. When the space character is discarded, the input carriage return is complete, which is normal.
Cin. Get is used to read characters. The input carriage return ends, but the carriage return and space characters are not discarded.
Note: cin. get () and CIN. get (char) is equivalent, but cin. get (char *, INT) is used to read strings. It can accept space characters. When the carriage return ends, the character is read according to the specified length (length minus 1), and the last carriage return is discarded.
Cin. getline () and CIN. get (char *, INT) has the same usage. The only difference is cin. when the string input by get (char *, INT) is too long, it will not cause the CIN function error, and subsequent CIN operations will continue to be executed. However, the former will cause the CIN function error, and subsequent CIN operations will not be executed.
2. scanf, getchar read characters
Scanf ("% C", & Ch)
Ch = getchar ()
The two are the same. They can be read based on the number of variables using space characters and carriage return characters.
3. scanf, gets read string
Scanf ("% s", STR) encounters a space character and a carriage return character. A space character and a carriage return character cannot be entered.
Gets (STR) stops when a carriage return ends, but spaces are allowed in the string. Do not discard the space character.