Difference between cin.get and cin.get line

please explain as i cant find which one to use where ?

@ivanshajkapoor https://ide.codingblocks.com/s/153730
Check the output of this code. Then change line no 6 to cin.getline(str1 , 100); and again check the output. You will get an unexpected output.
So,
cin.getline() reads input up to ‘\n’ and stops. Next input is expected from a new line.
cin.get() reads input up to ‘\n’ and keeps ‘\n’ in the stream

Relate it with the above code. I would suggest you to always use cin.getline when you want to extract strings line by line to remove the confusion.

Hope this helps :slightly_smiling_face:

2 Likes

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.