C++代码错误,需要修复
C++ code buggy, needs fixing
嘿伙计们,我有这段代码,发布在下面。我添加了 while 循环以确保只使用数字输入,但是当我使用它时,它需要我输入数字两次,或者按 Enter 然后输入数字。
输出将是:
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;
//}
}
去掉第一个cin >> x;
,在 while 之后设置string searchWord
相关文章:
- 将鼠标悬停在问题上时与预期">"相关的代码错误
- VI工作室代码错误无法打开输出文件主.exe
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- 有关矩阵的代码错误导致分段错误(内核转储)
- C++ Schannel POST 400 错误代码错误请求
- Java 本机访问代码错误:"Invalid memory access"
- 代码错误修改
- C++代码错误分配
- "_FCbuild"不能用作函数 - C/C++ 代码错误
- 我的代码错误类型警告 1 警告 C4018 和更多错误
- 代码错误(从 1 到 100 找到质数)
- OpenCV VisualStudio,C 代码错误尝试访问像素
- 当我使用的教程完全没有错误时,为什么我的代码错误
- 简单的NOOB C 输入/输出问题:代码错误
- 为什么enumProcessModules返回false值和299代码错误
- WinhttpSetoption()失败设置TLSV1.2,带有错误代码错误_internet_incorrect_ha
- 苹果安全传输代码错误
- C++ - 国际象棋主教移动代码错误
- 导入Python库时,嵌入了Python代码错误
- 编译提升C 代码错误