see a lot of C + + code written in Cin.get () after the comment said this is the absorption carriage return, do not know what it means!
See a lot of C + + code written in Cin.get () after the comment said this is the absorption carriage return, do not know what it means!
For example
cout<< "Please enter learn, age and entrance results:" <<endl;
cin>>st1.id>>st1.age>>st1.score;
Cin.get ();
Finally this cin.get () book said its function is to absorb carriage return, please expert guidance!
Characters have always
been difficult to manipulate because you enter the data is a carriage return as the end, but the carriage return is not entered into the program, if the following appear to enter the characters such as statements, then this carriage return is first entered, that is, there will be errors, so in the acquisition of data, Especially when several kinds of data are collected together, pay attention to the problem of carriage return.
The carriage return is left in the buffer, except that the CIN stream has a default state of skipping whitespace for the input operator (i.e. the ">>" operator), so whitespace characters such as carriage return are skipped by default when read with the input operator, which is actually in the buffer, You can use the NOSKIPWS operator to let the input operators not skip whitespace characters, so that you can read "\ n" and other white space, as follows:
//---------------------------------------------------- -----------------------
#include <iostream>
int main (void)
{
char m,n;
std::cin>>m;
std::cin>>std::noskipws>>n;//does not ignore whitespace characters
return 0;
}
---------------------------------------------------------------------------the
STD::SKIPWS operator to set the Ignore whitespace character.
Because Cin.get () is getting a character, the carriage return is also a character,
Cin.get () will read the carriage return (' \ n ') as a character. While cin>> skips a carriage return or a space