C++ getline method not working

前端 未结 4 1986
借酒劲吻你
借酒劲吻你 2021-01-24 23:41

I\'m sorry but I\'m quite new to C++ but not programming in general. So I tried to make a simple encryption/decryption. However when I added the modification to my previous code

4条回答
  •  执笔经年
    2021-01-24 23:58

    This is because you still have the newline character in the buffer which makes getline() stop reading as soon as it encounters it.

    Use cin.ignore() to ignore the newline character from the buffer. This will do in your case.

    In general, if you want to remove characters from your buffer untill a specific character, use:

    cin.ignore ( std::numeric_limits::max(), ch )
    

提交回复
热议问题