Why would we call cin.clear() and cin.ignore() after reading input?

后端 未结 4 1972
小蘑菇
小蘑菇 2020-11-21 22:59

Google Code University\'s C++ tutorial used to have this code:

// Description: Illustrate the use of cin to get input
// and how to recover from errors.

#in         


        
4条回答
  •  囚心锁ツ
    2020-11-21 23:57

    use cin.ignore(1000,'\n') to clear all of chars of the previous cin.get() in the buffer and it will choose to stop when it meet '\n' or 1000 chars first.

提交回复
热议问题