+ 1

What is cin.ignore(10, '\n') in C++?

Hello :) Pls excuse my bad english skills. In my Book for C++, theres everytime a cin.ignore(10,'\n'); at the end of the program. I do understand, that it ignores the "Enter" or "\n" then i input something in cin. But i dont quite understand, why it is 10? Its in every example in the book, with one cin >> number :) I hope somebody can explain it properly. Thanks in advance!

12th Aug 2017, 12:30 PM
Tech Piranja
Tech Piranja - avatar
3 Antworten
+ 13
istream& ignore(streamsize n = 1, int delim = EOF); The program "ignores" (extract and discard) n number of characters from the input stream, or, if the delimiting character is met before all n characters have been ignored. As for why most books put 10 in place of n, there is no real reason. I standardise stuff at 512, '\n' - i.e. chances of my clients effing up the program by banging their heads on their keyboards are pretty high.
12th Aug 2017, 12:53 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Wow, Thanks again @Hatsy!
12th Aug 2017, 1:53 PM
Manual
Manual - avatar
+ 1
Ah, Thanks alot @Hatsy :D
12th Aug 2017, 2:07 PM
Tech Piranja
Tech Piranja - avatar