双线,当要求用户按 i 查看库存时
Double Line when user is asked to press i to view Inventory
嘿 基本上我有 2 个函数:
void Inventory:: showInventory()
{
char input[80];
cin >> input;
char inventoryRequest[] = "i";
//compare the player input to inventoryRequest (i) to see if they want to
//look at inventory.
int invent = strcmp (input,inventoryRequest);
if(invent == 0) {
//vector<string> inventory;
cout << "You have " << inventory.size() << " items.n";
cout << "n******Inventory******";
cout << "nYour items:n";
for (int i= 0; i< inventory.size(); ++i) {
cout<< inventory[i] << endl;
}
}
}
void Inventory :: displayInventory(const string str) {
char input = 0;
do
{
cout << str << endl;
cin >> input;
}
while((input != 'i') && (input != 'I') && (input != 'n') && (input != 'N'));
showInventory();
//return input;
}
showInventory 将玩家输入与 i 进行比较。显示清单仅允许用户按 I 或 N。I 查看库存,n 跳过。但是当我被按下时。 它会导致双线。
这意味着我必须按两次才能查看库存。
我已经尝试了许多方法来阻止这种情况发生。 但我没有成功,大多数时候根本无法查看库存。
任何人都可以帮我解决这个问题。提前谢谢。
尝试在 void Inventory::showInventory()
上使用参数进行输入,并消除第二个cin
,如下所示:
void Inventory:: showInventory(char input)
{
//char input[80];
//cin >> input;
//char inventoryRequest[] = "i";
//int invent = strcmp (input,inventoryRequest);
//compare the player input to inventoryRequest (i) to see if they want to look at inventory.
//if(invent == 0) // REPLACE THIS WITH THE LINE BELOW
if(input == 'i')
然后当你调用它时,这样做:
showInventory(input);
相关文章:
- 多线程双缓冲区
- 双线程应用比单线程应用慢 C++ (VC++ 2010 Express).如何解决?
- 使用 task_group 的英特尔线程构建模块性能不佳(新用户)
- 用于在C++中计算用户数据的线程
- 如何将用户输入从控制台传递到不同线程中的对象 -> QTcpsocket
- 双变量输出 32767 始终代替用户输入
- 如何将每线程用户数据传递到ASIO处理程序中
- 如何在不让用户等待的情况下管理多个线程
- 在 C++11 中计算字母和单词的双字母组合的 std::线程向量的问题
- C++等待用户输入的中断线程
- Lua 关机双免费,关机期间 Lua 线程还活着?
- 在C 中的用户输入上加上长的双文字后缀
- 如何以双引号打破一条线
- 双参数构造函数的用户定义文本
- 双线,当要求用户按 i 查看库存时
- 将二进制树转换为双线程二进制树
- 如何调度/创建用户级线程,以及如何创建内核级线程
- 用户空间线程库
- wire.h外部双线对象错误
- 当用户双击qtablewidget标题时,c++ QT4检测