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 x 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 (End-Of-File). Typing Control-d into the terminal sends
this message.
Write a program in EOF_Sum/main.CPD 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 Metric/main.cpp 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:
10mm 14mm
14mm 10mm
12mm 12mm
1cm 10mm
12cm 99mm
12cm 200mm
1km 5677m
100000cm 1000m
Expected output:
10mm is smaller than 14mm
14mm is larger than 10mm
12mm is the same as 12mm
1cm is the same as 10mm
12cm is larger than 99mm
12cm is smaller than 200mm
1km is smaller than 5677m
100000cm is the same as 1000m
( In c + + ) Reading to EOF Input streams ( like

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!