How do I flush the cin buffer?

前端 未结 13 1078
無奈伤痛
無奈伤痛 2020-11-22 00:14

How do I clear the cin buffer in C++?

13条回答
  •  失恋的感觉
    2020-11-22 00:33

    Another possible (manual) solution is

    cin.clear();
    while (cin.get() != '\n') 
    {
        continue;
    }
    

    I cannot use fflush or cin.flush() with CLion so this came handy.

提交回复
热议问题