Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在不需要输入的情况下接收按键输入? i=0; 而(i_C++ - Fatal编程技术网

C++ 如何在不需要输入的情况下接收按键输入? i=0; 而(i

C++ 如何在不需要输入的情况下接收按键输入? i=0; 而(i,c++,C++,您只需要存储输入并将其与所需案例进行比较。仔细考虑一下 i=0; while(i<=20) { nullchoice: system("CLS"); //Advanced Information cout << "Your Statistics: " << endl; cout << endl << endl; cout << " 1 Strength: " <<

您只需要存储输入并将其与所需案例进行比较。仔细考虑一下

i=0;
while(i<=20)
{
    nullchoice:
    system("CLS");
    //Advanced Information
    cout << "Your Statistics: " << endl;
    cout << endl << endl;
    cout << "   1  Strength: " << str << endl;
    cout << endl;
    cout << "   2  Vitality: " << vit << endl;
    cout << endl;
    cout << "   3  Agility: " << agi << endl;
    cout << endl;
    cout << "   4  Thaumaturgy: " << tha << endl;
    cout << endl << endl;
    cout << "Points Remaining: " << lvlskills << endl;
    cout << endl;
    cout << "Enter the number of the skill you wish to increase: ";

    //Applying points to skill attributes

    if(i<=19)
    {
          cin >> input;

          if(input==1)
                str+=1;
          else if(input==2)
               vit+=1;
          else if(input==3)
               agi+=1;
          else if(input==4)
               tha+=1;
          else
               goto nullchoice;

         lvlskills-=1; 
    }    
    i++;
    cout << endl << endl;                     
}
do
{
系统(“CLS”);
//高级信息

一个相当可移植的解决方案是使用Curses库。你想用它做什么操作系统?这是针对Microsoft Windows的不,这不是一个重复的线程。其他解决方案包括如何接收按钮输入(getch、cin.get、pause>>nul等)。因此,如果我按“S”,它将继续,如果我按“R”我需要的是一个条件语句,这样程序就可以区分“R”和“S”其他问题中的答案解决了您的键盘输入问题。您还必须使用自己的大脑以您需要的方式使用收集的输入。这仍然需要用户按enter键。不..它没有..它经过测试..工作起来很有魅力。我现在明白了它的工作原理。谢谢!
do
{
    system("CLS");
    //Advanced Information
    cout << "Your Statistics: " << endl;
    cout << endl << endl;
    cout << "   1  Strength: " << str << endl;
    cout << endl;
    cout << "   2  Vitality: " << vit << endl;
    cout << endl;
    cout << "   3  Agility: " << agi << endl;
    cout << endl;
    cout << "   4  Thaumaturgy: " << tha << endl;
    cout << endl << endl;
    cout << "Points Remaining: " << lvlskills << endl;
    cout << endl;
    cout << "Enter the number of the skill you wish to increase: ";

    //Applying points to skill attributes
          char input;
          switch(input=getch()){
              case '1':
                str+=1;
                lvlskills-=1;
                break;
          case '2':
               vit+=1;
               lvlskills-=1;
               break;
          case '3':
               agi+=1;
               lvlskills-=1;
               break;
          case '4':
               tha+=1;
               lvlskills-=1;
         } 
    cout << endl << endl;                     
} while(lvlskills>0);