Getline ignoring first character of input

前端 未结 3 1141
遥遥无期
遥遥无期 2020-12-11 04:20

I\'m just starting with arrays in C++ and I\'m having a problem getting the first character of an array.

This is my code,

1- I enter a name, such as \"Jim\"<

3条回答
  •  眼角桃花
    2020-12-11 05:04

    Here is signature of cin.ignore:

    istream& ignore (streamsize n = 1, int delim = EOF);
    

    So if you call ignore function without any parameters, it will ignore '1' char by default from input. In this case it ignored 'J'. Remove ignore call and you will get 'Jim'.

提交回复
热议问题