+ 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!
3 Answers
+ 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.
+ 3
Wow,
Thanks again @Hatsy!
+ 1
Ah, Thanks alot @Hatsy :D