getline() skipping first even after clear()

前端 未结 4 2045
终归单人心
终归单人心 2021-01-02 05:16

So I have a function that keeps skipping over the first getline and straight to the second one. I tried to clear the buffer but still no luck, what\'s going on?



        
4条回答
  •  忘掉有多难
    2021-01-02 05:41

    cin.clear(); clears any error bits on the stream - it does not consume any data that may be pending.

    You want to use cin.ignore() to consume data from the stream.

提交回复
热议问题