0

I was just curious; what exactly does the line cin.ignore(INT_MAX) actually do? I was always told to use it just to keep the program screen up when inputting something.

5
Contributors
4
Replies
6
Views
9 Years
Discussion Span
Last Post by Nick Evan
0

It removes up to INT_MAX characters from the input buffer, basically clearing the buffer.

Couldn't understand. Please simplify the use of it.

0

From this thread by Narue

#include <ios>
#include <istream>
#include <limits>

void ignore_line ( std::istream& in )
{
  in.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
}

The ignore member function of std::istream will read and discard up to N characters or until a delimiter. In the above example, N is represented by the largest value of the streamsize data type, and the delimiter is a newline. It works equally well with just a large value (80 is common):

in.ignore ( 80, '\n' );
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.