嘿伙计们,我有这段代码,贴在下面。我添加了while循环以确保只使用数字输入,但是当我使用它时,它需要我输入两次数字,或者按回车然后输入数字。
输出将是:
Input number : 1
1
然后它会打印结果。我该如何解决这个干杯。
void Dictionary::SearchNumeric()
{
int x;
cout << "Input number : ";
while (!(cin >> x))
{
cout << "Invalid input. Try again: ";
cin.ignore(numeric_limits<streamsize>::max());
}
string searchWord = myWords[x]->word;
cout << "Word searched: " << searchWord << endl;
cout << "Definition: \n" << myWords[x]->definition << endl;
cout << "Type: " << myWords[x]->type << endl;
int wordIndex = 0;
//while (myWords[wordIndex]->word.compare(x) != 0) {
//needs to return scrabble score
wordIndex++;
//break;
//}
}