Wednesday, February 19, 2014

IO problem

Newsgroup: comp.lang.c++

Subject: IO problem

From: nvangogh <nvangogh@...>

Date: Wed, 19 Feb 2014 14:29:18 +0000



I have come to a question in C++ Primer (p 314 , exercise 8.1) that is

not clear to me.

"Write a function that takes and returns an istream&. The function

should read the stream until it hits end-of-file. The function should

print what it reads to the standard output. Reset the stream so that it

is valid before returning the stream."



Breaking this down, the function has to do three things:



1. Read a stream until it hits end-of-file

So the >> operator reads input from an istream object - cin.

This stream's end of file can be interrogated by

cin.eof(). This returns true if the end of file bit is set which can be

tested with a bool variable

bool on = false;

on = cin.eof();

if(on == true)

// end of file is reached, else

if(on ==false)

// keep reading cin



I don't believe that this is completely correct so can someone show me

how this code should be presented?



2. Print what is read to the standard output

I can only imagine this to be cout << ? But am lost from here



3. Reset the stream so it is valid before returning the stream

This section of the problem again defeats me.



Can anyone help with this function?









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KSh

View all the progranning help forums at:

http://ift.tt/1dP9txN

No comments:

Post a Comment