我正在尝试使用getline读取一串文本.出于某种原因,它会打印两次"请输入您的选择":
Please enter your selection
Please enter your selection
Run Code Online (Sandbox Code Playgroud)
如果我键入无效文本,它会再次循环,并且此后每次循环只打印一次.
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.
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道为什么会这样?
谢谢