1
With the em(extraction) operator, a similar situation holds true as with the
2
insertion operator, the extraction operator operating comparably to the
3
tt(scanf()) function. I.e., white space characters are skipped. Also, the
4
operator doesn't expect em(pointers) to variables that should be given new
5
values, but em(references) (with the exception of the tt(char *), but
6
tt(string) variables are used as references).
8
Consider the following code:
17
cin >> i1 >> i2; // see (1)
19
while (cin >> c && c != '.') // see (2)
29
This example shows several characteristics of the extraction operator worth
30
noting. Assume the input consists of the following lines:
38
that we're not yet done
43
eit() In the first part of the example two int values are extracted
45
these values are assigned, respectively, to tt(i1) and tt(i2).
46
White-space (newlines, spaces, tabs) is skipped, and the values
47
125 and 22 are assigned to tt(i1) and tt(i2).
49
If the assignment em(fails), e.g., when there are no numbers to be
50
converted, the result of the extraction operator evaluates to a zero
51
result, which can be used for testing purposes, as in:
53
center(tt(if (!(cin >> i1))))
54
eit() In the second part, characters are read. However, white space is
55
skipped, so the characters of the words tt(hello) and tt(world) are
56
produced by tt(cin), but the blanks that appear in between are not.
58
Furthermore, the final tt('.') is not processed, since that one's
59
used as a sentinel: the delimiter to end the tt(while)-loop, when the
60
extraction is still successful.
61
eit() In the third part, the argument of the extraction operator is yet
62
another type of variable: when a tt(char *) is passed, white-space
63
delimited strings are extracted. So, here the words tt(this, example,
64
shows, that, we're, not, yet, done, with) and tt(C++) are returned.
66
Then, the end of the information is reached. This has two consequences:
67
First, the tt(while)-loop terminates. Second, an empty string is
68
copied into the tt(buffer) variable.