Read a list of string

What is the use of cin.get( ) which is used in code after cin>>n.
For reading string we already use cin .getline

Hey @Alfred cin.get() is used for accessing character array. It includes white space characters. Generally, cin with an extraction operator (>>) terminates when whitespace is found. However, cin.get() reads a string with the whitespace.
Whereas, getline() is a standard library function that is used to read a string or a line from an input stream. It is a part of the header . The getline() function extracts characters from the input stream and appends it to the string object until the delimiting character is encountered. While doing so the previously stored value in the string object str will be replaced by the input string if any.

But wee use cin.get after reading cin>>n where n is an integer if we don’t use cin.get then there is any problem.

See the basic difference between cin.get and cin>> is that in cin.get we can take a string which doesn’t have any space in it like “kjndfjbfjg” so to store it in a string we will use cin.get whereas if there is any space in a string and we have to store that in an array, then what we will do is use getline . It’s use to get string like this “jsdfsbs eiuj buhf ei h” so the entire string will be stored in a string variable
and as of cin>>n you know that it will work only for integer values.

So I am just asking that there is no need to use cin.get() since we are already using cin.getline in the read list of string code

Yes, if you are using cin.getline() function then there won’t be as much need of cin.get()

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.