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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25020129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:13:22  来源:igfitidea点击:

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

c++cinignore

提问by Zyi

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

cin.ignore(numeric_limits<streamsize>::max(), '\n')在 C++中是什么意思?

Does it actually ignore the last input from the user?

它实际上是否忽略了用户的最后输入?

回答by dasblinkenlight

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

此行忽略当前行的其余部分,直到'\n'EOF- 以先到者为准:

  • '\n'sets the delimiter, i.e. the character after which cinstops 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 cinthat there is no limit to the number of characters to ignore.
  • '\n'设置分隔符,即cin停止忽略的字符
  • numeric_limits<streamsize>::max()设置要忽略的最大字符数。由于这是流大小的上限,因此您实际上cin是在告诉要忽略的字符数没有限制。

回答by Akash sharma

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

cin.ignore(numeric_limits <流大小> ::max(), '\n');

Here, the \nacts as a delimiter.... that is the point upto which the code has to be ignored(as "\n" in this perticular case). And max()defines that there is no limit for how much can be ignored, the spaces, tabs have to be ignored untill the line ends.

在这里,\n作为分隔符......这是代码必须被忽略的点(在这种特定情况下为“\n”)。并max()定义了可以忽略的数量没有限制,必须忽略空格,制表符,直到行结束。