After using cin>>n, what is the use of writing cin.get( ).
Use of cin.get( ) after cin>>n
If after input number we use cin.getline() then the enter after input is not considered as the first string so in order to prevent it cin.get() is used.
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.
Prateek bhaiya told in the tutorial that cin.get( ) is used to consume any extra enter after \n. I just wanna know that what he exactly wanna say?
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.
@yashpundhir54,
When you would give input, it would be like
5(=n) (Enter aka new line)
asdsdaf
etc
now cin>>n, will get that 5, but there would still be a new_line char left, to capture that we use cin.get,
else get line would capture it and consider it a string, which we clearly don’t want.
thank you Abhijeet Srivastava… it really helped me
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.