tell cin to stop reading at newline

后端 未结 6 1402
[愿得一人]
[愿得一人] 2020-11-28 11:27

Suppose I want to read line a of integers from input like this:

1 2 3 4 5\\n

I want cin to stop at \'\\n\' character but cin doesn\'t seem

6条回答
  •  情话喂你
    2020-11-28 11:43

    getchar() is more efficient than cin when working with characters at this situation

    I tried to do the same with a line of characters with unknown length and want it to stop at a newline but it has an infinite loop and haven't detect the newline, so I just used getchar() instead of cin and it works

提交回复
热议问题