Working with Streams 603
17
Int: 2
Long: 30303
Double: 393939397834
Float: 3.33
Word: Hello
Unsigned: 85
Int: 2
Long: 30303
Double: 3.93939e+011
Float: 3.33
Word: Hello
Unsigned: 85
Int, Long, Double, Float, Word, Unsigned: 3 304938 393847473 6.66 bye -2
Int: 3
Long: 304938
Double: 3.93847e+008
Float: 6.66
Word: bye
Unsigned: 4294967294
Again, several variables are created, this time including a chararray. The user is
prompted for input and the output is faithfully printed.
On line 34, the user is prompted for all the input at once, and then each “word” of input
is assigned to the appropriate variable. It is to facilitate this kind of multiple assignment
that cinmust consider each word in the input to be the full input for each variable. If cin
was to consider the entire input to be part of one variable’s input, this kind of concate-
nated input would be impossible.
Note that on line 42, the last object requested was an unsignedinteger, but the user
entered -2. Because cinbelieves it is writing to an unsignedinteger, the bit pattern of -2
was evaluated as an unsignedinteger, and when written out by cout, the value
4294967294 was displayed. The unsignedvalue 4294967294 has the exact bit pattern of
the signedvalue -2.
Later today, you will see how to enter an entire string into a buffer, including multiple
words. For now, the question arises, “How does the extraction operator manage this trick
of concatenation?”
The cinReturn Value ....................................................................................
The return value of cinis a reference to an istreamobject. Because cinitself is an
istreamobject, the return value of one extraction operation can be the input to the next
extraction.
OUTPUT
ANALYSIS