Question: ( In c + + ) Reading to EOF Input streams ( like std::cin ) can be used as predicates ( bools ) to see
In c
Reading to EOF
Input streams like std::cin can be used as predicates bools to see if
they are in an error state. One such error state is having no more data to
read in So an expression like this,
while std::cin
will loop until cin has nothing more to read. The expression cin
extracts a value from the stream and puts it in but it also returns
So this statement:
while std::cin x
will keep replacing with the next value from a stream until the stream
is exhausted.
When you are testing your code by compiling and running it the above
example will run until you specify that there is no more input. This is
called the EOF EndOfFile Typing Controld into the terminal sends
this message.
Write a program in EOFSummainCPD that reads in integers from the
standard input stream until there are no more values. Print the sum of
those integers.
Example input:Write a program in Metricmaincpp that reads pairs of metric distances mm cm m or km from the standard input stream until there are no more values. For each pair, print if the first distance is larger than the second.
Example input:
mm mm
mm mm
mm mm
cm mm
cm mm
cm mm
km m
cm m
Expected output:
mm is smaller than mm
mm is larger than mm
mm is the same as mm
cm is the same as mm
cm is larger than mm
cm is smaller than mm
km is smaller than m
cm is the same as m
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
