Tuesday, 15 March 2016

Listing 4.6 illustrates a problem created by following numeric input with line-oriented string input.How would replacing this

Leave a Comment

Question:

Listing 4.6 illustrates a problem created by following numeric input with line-oriented string input.How would replacing this:

             cin.getline(address,80);
with this:
             cin >> address;
affect the working of this program?

Answer:

Using cin >> address causes a program to skip over whitespace until it finds nonwhitespace.
It then reads characters until it encounters whitespace again.Thus, it
will skip over the newline following the numeric input, avoiding that problem. On
the other hand, it will read just a single word, not an entire line.

Source:

C++ Primer Plus Sixth Edition Chapter Review

If You Enjoyed This, Take 5 Seconds To Share It