+ 2

What does this two syntax mean in c++?

cin.ignore(10, '\n'); and cin.get(); what does this two syntax mean?

29th May 2017, 7:10 AM
Emi
Emi - avatar
1 Respuesta
+ 5
cin.ignore() is a istream function used to ignore characters entered into the input stream... The function recieves 2 arguments, the first containing the number of characters to ignore and the second is a delimiter to stop ignoring. If you simply use cin.ignore(), it will just ignore the last character entered... So, cin.ignore(10,'\n') will ignore 10 characters from input stream but stop at <10 if \n is encountered... cin.get() is a method function used to extract one character, whatever it may be, from the input stream. It can even read spaces, newlines, etc. Its overload allows one to read more than one character from the stream, the first argument specifying the array to store the characters and the second to specify no of chars to read. There is an optional 3rd argument for specifying a delimiter, to stop reading..., usually newline...
29th May 2017, 7:40 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar