Use of get function

after running this code it takes only 2 inputs when I give 3, if I don’t type cin.get( ) after cin>>n.

why does this happen?

also why does it take perfectly 3 inputs after typing 3. When not including cin.get() after cin>>n. And instead of typing for(int i=0; i<n ; i++), typing for(int i=0; i<=n ; i++) works, Shouldn’t for(int i=0; i<=n ; i++) be taking 4 inputs if i type 3?

@Souradeep-Kundu-824545687968212 “cin” reads only till the space of new line, and leaves the pointer pointing at that position only, after that if we use getline() it will start at that position only and would read the end of line and stop.
Now the next getline() will read the next complete line.
So on using 2 getline() we have read only 1 string as first getline reads only the end of line.
So it becomes necessary to use cin.get() if we want to use getline() after cin , as that will complete the line and we will move to next line for reading.
If this resolves your doubt mark it as resolved.

what about my second question

@Souradeep-Kundu-824545687968212 that is all I have said in the answer. You using for loop, n+1 times instead of n will obviously help in reading all the strings. As it is the first getline() that reads the blank, after that each getline will read a string. So use 1 extra getline then it will compensate for reading blank.
If this resolves your doubt mark it as resolved.

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.