Some problems in this lecture

Ques1) what is cin.get() doing in line no 13. ?

Ques2) in this statement cin.get(name, no) why do we write any no. here ??
what does that no tell ?? what is the significance of that no ?

and what is cin.getline(name,no) why there is line ??

@anujsharmabadboy

  1. after we take input n, there will be a newline character (to separate the inputs). getline reads till the end of line, so it will encounter the end of line character and stop reading the input. So to counter this problem, we use cin.get() to read that “\n” character so that the rest of the input can be read without any hassle.
  2. There is no function cin.get(name, no). get() and getline() are two separate functions. They are not the same and it is not a typo with an extra “line”.
  3. cin.getline(name, num) num signifies the maximum number of characters to be read. Since our string can be only of 1000 length (because size of array is 100 * 1000) it means that maximum 1000 characters will be read. It is important to mention this because geline reads input till end of line, but what if end of line character is never encountered? Hence we provide a limit on number of characters.
1 Like

@anujsharmabadboy do you still have any doubts? FYI, enter is treated as a character too. In fact, “enter” IS the new line character I am talking about. It is denoted by ‘\n’.

yeah, i know that …
thank you

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.