Not able to understand ch=cin.get() statement use in program


“when ch=cin.get() statement not used then wrong output is coming as can be seen in image”

“but when it is used at line 12 my output is coming correct
not able to understand what the statement doing at that place.”
“question from video of reading sentences.”

Hello @amit_coder333 cin.get is done first to check id any character is already there in buffer so if you arr not doing that that’s why your output is coming different.
There are two ways to input a string - cin.get(s) and cin.getline(s)
cin.getline() is used to input white spaces as well.
For example, if the input string is “Hello World”.
If we used cin.get(s), cout<<s will display “Hello”.
If we used cin.getline(s), cout<<s will display “Hello World”.

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.