【问题标题】:Press the 'enter' key to move forward [duplicate]按“输入”键向前移动[重复]
【发布时间】:2014-05-22 02:39:07
【问题描述】:

我希望我的程序仅在按下 enter 键(而不是任何其他键)时继续前进。

这是我目前所拥有的:

while (getline(in, line) )   {

                cout << line << endl;;

                cin.ignore();
}

【问题讨论】:

  • 你的问题是?

标签: c++ keyboard-input


【解决方案1】:

ignore 接受分隔符参数:

basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() );

你可以这样使用它:

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

【讨论】:

  • while(getchar()=='\n'); WTF
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 2016-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多