Program skips cin.getline()

前端 未结 5 1789
野的像风
野的像风 2020-12-19 12:18

I have made this program, It get the users adress, name and work. Then It puts it all into one string and outputs that string. (I know there are better ways to do this)

5条回答
  •  春和景丽
    2020-12-19 12:33

    Your logic is sound, the issue is that when you declare a char array of size 10, you don't actually get 10 spots to put characters in, you only get nine. The last one is reserved to signify the end of the string. [Here ][1] is a reference is you would like to read up more on the issue:

    Just declare one character more than the number you want. There are many excellent tips on how to flush the stream, ignore the rest of the line, etc that you can use as well.

    Good luck!

提交回复
热议问题