【问题标题】:How to Let Players Press Any Key to Continue?如何让玩家按任意键继续?
【发布时间】:2014-03-19 05:15:39
【问题描述】:

我想让玩家按任意键继续游戏,但不知道怎么做。这是我到目前为止的代码:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout << "\t\tWelcome to my first game, A Hero's Journey!\n\n";
    char response;
    cout << "\t\t\tPress any key to continue!: \n\n";
    cin >> response;
    if (response == 
    return 0;
}

我目前正在处理 if 语句,所以不要理会它,除非我决定玩家是否按下了某些东西。

【问题讨论】:

标签: c++ user-input


【解决方案1】:

不需要 if 条件,因为 cin 将始终等待输入。如果您要求用户输入特定的键,那么您需要一个 if 条件来检查它。

【讨论】:

  • 感谢您的信息,我以前经常这样做,但这些年来变得相当生疏。
猜你喜欢
  • 2010-11-29
  • 2020-08-10
  • 1970-01-01
  • 2013-11-10
  • 2015-01-23
  • 1970-01-01
  • 1970-01-01
  • 2011-12-13
  • 2020-03-14
相关资源
最近更新 更多