Which of the following are correct ways to end a loop using a test for end-of-file?

a) ```
while(inStream->next)
{
cout << next;
}
```

b) ```
while(inStream >> next)
cout << next;
```

c) ```
inStream.get(next)
while(!inStream.eof( ))
{
cout << next;
inStream.get(next);
}
```

d) ```
inStream.get(next)
while(!eof(inStream))
{
cout << next;
inStream.get(next);
}
```

e) None of the above. You cannot control a loop using a test for end of file.

b) ```
while(inStream >> next)
cout << next;
```

and

c) ```
inStream.get(next)
while(!inStream.eof( ))
{
cout << next;
inStream.get(next);
}
```

Part a) The answer mistakes -> (access to a member through a pointer) for >> (overloaded operator to do stream extraction. Part b) the inStream>>next returns a reference to a inStream object. The stream class has a conversion that is automatically called in this context to convert a stream in a good state to true, and a stream in a bad state to false. Part c) supplies the details. Part d) mistakes the eof member function to be a standalone function.

Computer Science & Information Technology

You might also like to view...

A pie chart represents a percent to a whole

Indicate whether the statement is true or false

Computer Science & Information Technology

“All instructions should have the ‘natural’ number of operands” and “all operands should have the same generality in specification” are two criteria that were used in designing the __________ instruction format.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology