How do I flush the cin buffer?

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

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

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 00:24

    The following should work:

    cin.flush();
    

    On some systems it's not available and then you can use:

    cin.ignore(INT_MAX);
    

提交回复
热议问题