1 2 3 4 5 6 7 8
|
char ch;
cin >> ch; // read one character
cin.putback( ch ); // put the character back to the stream
// cin has now same content as before line 2
// (if we ignore the whitespaceskipping)
double val;
cin >> val; // read a double value from stream
|
What does line 8 do?
http://www.cplusplus.com/reference/istream/basic_istream/operator%3E%3E/
"Extracts and parses characters sequentially from the stream to interpret them as the representation of a value of the proper type, which is stored as the value of val."
"Sets
failbit, if either no characters were extracted, or the characters extracted could not be interpreted as a valid value of the appropriate type."
The stream had
and after first get_token it still has:
and 2.0 is stored in t.value.
If the stream had had
then after first get_token it still has:
and 2.54 is stored in t.value.
If the stream had had
then after first get_token it still has:
and 0.7 is stored in t.value.
If the stream had had
then after first get_token it still has:
and 6.1 is stored in t.value, but the next get_token would encounter an error, because
f
is not a valid token.