How do I flush the cin buffer?

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

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

13条回答
  •  青春惊慌失措
    2020-11-22 00:36

    Easiest way:

    cin.seekg(0,ios::end);
    cin.clear();
    

    It just positions the cin pointer at the end of the stdin stream and cin.clear() clears all error flags such as the EOF flag.

提交回复
热议问题