Getline keeps on getting newline character. How can I avoid this?

前端 未结 6 1708
离开以前
离开以前 2020-12-14 23:56

Basically I first takes an integer as input and then test case follows. My each test case is an string. I am suppose to print the string back if the starting patten of strin

6条回答
  •  感动是毒
    2020-12-15 00:32

    Your cin >>N stops at the first non-numeric character, which is the newline. This you have a getline to read past it, that's good.

    Each additional getline after that reads the entire line, including the newline at the end. By putting in a second getline you're skipping half your input.

提交回复
热议问题