Operator overloading and, in particular, looking at argument types in
overloads for << and >> may help you understand, what’s going under the hood.
In short: those are just functions, which accept a reference to the stream and a reference to the variable. There is a separate overload for each type:
int,
double, and so on. Each is a function, that has its own internal logic of parsing data and puts the result into the variable it received as the argument.
The entire
stream >> a >> b expression may be seen as equivalent to:
read(stream, a); read(stream, b).
(1) All variables passed as references, so
read may put values into them.
As for the Stroustrup’s book: I can’t comment, as I don’t remember that anymore. But note that your use of
perror function is invalid there.
perror, aside from being a C relic, is meant to report
errno codes. You can’t use it arbitrarily to just write any text.
(1) More accurately this should be:
read(read(stream, a), b). That’s because the result of first
stream >> a is a stream reference itself, which is passed directly to the next
>> invocation.