_getch不将输入读入变量
_getch not reading input into variable
我在使用 _getch() 函数时遇到问题,我希望它使用户在从菜单中选择内容时无需按 ENTER。但是,当我尝试使用它时,它要么不将数据输入到变量中,要么跳过我拥有的开关。我使用的是Windows 7和CodeBlocks 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 anythingnthat has happened before you waking up. You seem to be some type of...n";
cout << "--CHARACTER SELECTION--n1. Warriorn2. Magen3. Rouge";
cin.get();
};
int main()
{
// CreateDirectory()
cout << "--SELECTION MENU--n1. Beginn2. Delete Gamen3. Instructions" << endl;
a=_getch();
switch(a){
case 1:
play();
break;
case 2:
// delete();
break;
case 3:
// help();
break;
return 0;
}
}
将您的字符与字符'1'
、'2'
和'3'
进行比较,而不是整数1
、2
和 3
进行比较。
switch(a){
case '1':
play();
break;
case '2':
// delete();
break;
case '3':
// help();
break;
return 0;
}
相关文章:
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 堆栈中大小变量输入错误 (C++)
- 如何使用用户输入变量制作二维数组?
- 一个变量的输入值也会保存到另一个变量中
- 如何在循环之外重新输入变量
- 我的 c++ 程序似乎没有发现字符串和我拥有但输入使用 getline 的变量之间的比较
- 使用单个变量对字符输入进行计数
- 如何在C++中从标准输入中获取变量输入
- 用户无法为第二个变量输入。C++
- C 错误:从命令行输入更改为变量输入
- 基于变量输入的泛型类方法计算
- 为什么我不能继续使用 std::cin 向同一变量输入其他值?
- 如何使用同一变量输入字母和数字?(C )
- C++:为什么为"int"变量输入"char"会导致递归变得疯狂?
- C++ 用户为整数变量输入非整数值
- 循环以丢弃来自stdin、Linux C++的虚假变量输入
- 如何通过cin为2个以上的变量输入流
- 为char类型变量输入多个字符的影响
- 接收从PHP到c++的各种变量输入
- 控制台应用程序-用户可以为c++中的整数变量输入的最高值是多少