Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.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++ _getch未将输入读取到变量中_C++_Getch - Fatal编程技术网

C++ _getch未将输入读取到变量中

C++ _getch未将输入读取到变量中,c++,getch,C++,Getch,我在使用_getch()函数时遇到了问题,我希望它能够让用户在从菜单中选择内容时不必按ENTER键。然而,当我尝试使用它时,它要么不将数据输入变量,要么跳过我的开关。我正在使用Windows7和代码块IDE。我做错了什么?提前谢谢 #include <iostream> #include <sstream> #include <conio.h> using namespace std; stringstream ss; int a; void play(

我在使用_getch()函数时遇到了问题,我希望它能够让用户在从菜单中选择内容时不必按ENTER键。然而,当我尝试使用它时,它要么不将数据输入变量,要么跳过我的开关。我正在使用Windows7和代码块IDE。我做错了什么?提前谢谢

#include <iostream>
#include <sstream>
#include <conio.h>

using namespace std;

stringstream ss;
int a;

void play()
{
  cout << "\nYou wake up on the forest floor. You do not remember where you are, who you are, or anything\nthat has happened before you waking up. You seem to be some type of...\n";
  cout << "--CHARACTER SELECTION--\n1. Warrior\n2. Mage\n3. Rouge";
  cin.get();
};


int main()
{
//  CreateDirectory()
  cout << "--SELECTION MENU--\n1. Begin\n2. Delete Game\n3. Instructions" << endl;
  a=_getch();


  switch(a){

  case 1:
  play();
  break;

  case 2:
 // delete();
  break;

  case 3:
 // help();
  break;
  return 0;
  }
}
#包括
#包括
#包括
使用名称空间std;
细流ss;
INTA;
无效播放()
{

无法将字符与字符
'1'
'2'
'3'
进行比较,而不是与整数
1
2
3
进行比较

switch(a){

  case '1':
  play();
  break;

  case '2':
 // delete();
  break;

  case '3':
 // help();
  break;
  return 0;
}

这对_getch()部分没有帮助,但我可以看到它将来可能会导致问题。谢谢!编辑:我明白了!谢谢!这就解决了问题。