Wednesday, January 18, 2012

cin string with white spaces

We use cin to store the user input to a specific variable.
Its limitation is when we try to save a string with white spaces (several words are involved).



The user input is "Hello there! Are you okay?", but only the first word, "Hello" is stored to variable str.


To include all words, we will use the function getline().





If you want to know more about getline(), visit the link below.

http://www.cplusplus.com/reference/string/getline/

No comments:

Post a Comment