Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cin.ignore(numeric_limits<streamsize>::max(), '\n')

Tags:

c++

cin

What does cin.ignore(numeric_limits<streamsize>::max(), '\n') mean in C++?

Does it actually ignore the last input from the user?

like image 470
Zyi Avatar asked Jul 29 '14 16:07

Zyi


People also ask

What is the significance of CIN ignore Numeric_limits Streamsize >:: max () '\ n ');?

'\n' sets the delimiter, i.e. the character after which cin stops ignoring. numeric_limits<streamsize>::max() sets the maximum number of characters to ignore. Since this is the upper limit on the size of a stream, you are effectively telling cin that there is no limit to the number of characters to ignore.

What does Cin ignore () do?

The cin. ignore() function is used which is used to ignore or clear one or more characters from the input buffer.

How do I ignore a character in C++?

The std::basic_istream::ignore is used to extracts characters from the input string and discards them including delimiting character, i.e., if the end of the file is reached this function stops extracting characters. The delimiting character is the new line character i.e '\n'.

What is CIN ignore in Java?

In java equivalent of cin.ignore() is InputStream.skip() . You can refer to Java Docs. Follow this answer to receive notifications.


1 Answers

This line ignores the rest of the current line, up to '\n' or EOF - whichever comes first:

  • '\n' sets the delimiter, i.e. the character after which cin stops ignoring
  • numeric_limits<streamsize>::max() sets the maximum number of characters to ignore. Since this is the upper limit on the size of a stream, you are effectively telling cin that there is no limit to the number of characters to ignore.
like image 173
Sergey Kalinichenko Avatar answered Sep 19 '22 13:09

Sergey Kalinichenko