嘿基本上我有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 跳过。但是当我被按下时。它会导致双线。
这意味着我必须按两次才能查看库存。
我已经尝试了很多方法来阻止这种情况的发生。但我没有成功,而且大多数时候根本无法查看库存。
任何人都可以帮我解决这个问题。提前致谢。