Why not cin.get(a) for first string

sir in first input sir has taken cin.get() but we have to compare strings so why it is not cin.get(a) for storing first input of strings . how could it compare it it is not mentioned to take in a . as we have done with cin.getline(a,1000)

and i am not able to send you the screenshot of code explained by sir. so please tell me how to do it.

hello @tejuschaturvedi0

are u asking about the line cin.get() that is written before the for loop?

pls clarify

ss

are u asking about line 20?

Yes please explain the role of it in the code.

that is not for reading first string.
instead we are using that to read \n that is left in the buffer after reading the integer.

You mean without it we give input in continuous line without giving space in any row.

ok wait,
first run this program and tell me what u r getting in output.
then after i will explain why we are getting such output.

It is not showing anything on running

yes … becuase getline(cin,s) is reading \n in place of abc string.

so to resolve this issue. what we have to do is first we need to remove \n from the buffer. for that we are using cin.get() it will read \n and after that when we read we will get abc.

now run and see->

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.