home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,283 of 33,346   
   nvangogh to All   
   C++ Input Output problem   
   17 Feb 14 21:33:33   
   
   From: nvangogh@pcexpert.net   
      
   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?   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca