Cin.get() fundamentals 2

while taking the characters n printing them it is instructed to use ch= cin.get even at the start to avoid storing garbage values but without using it also we are getting the correct output .

Hey @utkarsh2504
Use of cin.get() is actually situation dependent
Let’s say you just took some input after which you need to take a line as input
After the previous input the user usually presses enter or space
so if you do getline(cin,string);
string will store nothing of the line you wanted

thnku also will it not the store the lines n words after the space or enter button?

@utkarsh2504
No it won’t
Space and enter are delimiters
getline takes input before delimiter
Since first value is delimiter ( space or enter )
Nothing is stored in string

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.