cin.ignore()

I was following some tutorials and i noticed that they use cin.ignore(255, '\n'); a lot. I understand that this forces the program to wait for user input before exiting the program, but what are the 255 and '\n' statements for?
255 - The number of elements to skip from the current read position.

\n - The element that, if encountered before 255, causes ignore to return and allowing all elements after \n to be read.
http://www.cplusplus.com/reference/iostream/istream/ignore/

255 equals how many characters are accepted in the buffer before program ends. The '\n' is delimeter that need to be found from stream before program ends.

Even 1 of those two 2 conditions need to be met to program continue. Check out following code. Program ends either:
a) 20 characters are given or
b) there is a spacebar writed

1
2
3
4
5
6
7
#include <iostream>

int main()
{
        std::cin.ignore(20, ' ');
        return 0;
}
Topic archived. No new replies allowed.