Reading string input a word at a time is often not the most desirable choice. For instance, suppose a program asks the user to enter a city, and the user responds with
New York or
Sao Paulo. You would want the program to read and store the full names, not just
Sao. To be able to enter whole phrases instead of single words as a string, you need a different approach to string input. Specifically, you need a line-oriented method instead of a word-oriented method. You are in luck, for the
istream class, of which
cin is an example, has some line-oriented class member functions:
get(). Both read an entire input line—that is, up until a newline character. However,
getline() then discards the ...