我正在尝试使用 getline 读取一串文本。出于某种原因,它会打印两次“请输入您的选择”:
Please enter your selection
Please enter your selection
如果我键入无效文本,它会再次循环,并且此后每次循环仅打印一次。
while (valid == false) {
cout << "Please enter your selection" << endl;
getline (cin,selection);
// I have a function here which checks if the string is valid and sets it to true
// if it is valid. This function works fine, so I have not included it here. The while
// look breaks correctly if the user enters valid input.
}
有谁知道为什么会发生这种情况?
谢谢