清除Cin缓冲区不起作用

时间:2016-02-19 07:39:36

标签: c++ buffer cin

我正在开始一个菜单程序的开头,我无法清除cin缓冲区。我尝试过cin.ignore,sync,clear等几个东西。我不知道为什么这个循环不等待输入,只是重复无穷大。

do
{
    cout << "Enter One of the Following Choices: \n"<<
    "A: Carnivore       C: Pianist\n" <<
    "B: Tree            D: Game\n"<< "You must enter A,B,C,D: \n";
    //getline(cin,tmp);cin.ignore();cin.sync();cin.clear();
    cin.get(choice);

}while(choice!='A' && choice!='B' && choice!='C' && choice!='D');

0 个答案:

没有答案
相关问题