home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13690 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  1.4 KB

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!seismo!lll-winken!sundance!moonshine!jac
  2. From: jac@moonshine.llnl.gov (James A. Crotinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: iostreams inheritance question
  5. Message-ID: <jac.716576895@moonshine>
  6. Date: 15 Sep 92 17:08:15 GMT
  7. References: <BuL958.1MH@nntp-sc.Intel.COM>
  8. Sender: news@sundance.llnl.gov (News Administrator)
  9. Organization: Magnetic Fusion Energy - LLNL
  10. Lines: 27
  11.  
  12. rcox@cad734.NoSubdomain.NoDomain (Richard Cox) writes:
  13. > main () 
  14. > {
  15. >     ios &out = cout;
  16. >     out << "Grateful Dead" << endl;   // this is line #13
  17. > }
  18.  
  19. > but I get the followin errors:
  20.  
  21. > "streamT.C", line 13: error: bad operand types ios  char [14] for <<
  22. > "streamT.C", line 13: error:  function operand for  <<
  23.  
  24.   The problem is that it is iostream which provides all of the
  25. operator<<() and operator>>() definitions. ios doesn't have such
  26. member functions, so the above code doesn't make sense.
  27.  
  28.   On the other hand, fstream does inherit from iostream. Thus 
  29. you should be able to just declare "out" to be a reference to
  30. an iostream, and initialize it with an fstream if you want to
  31. do file I/O. 
  32.  
  33.   Jim
  34. --
  35. -------------------------------------------------/\--------------------------
  36. James A. Crotinger     Lawrence Livermore N'Lab // \ The above views are mine
  37. jac@moonshine.llnl.gov P.O. Box 808;  L-630 \\ //---\  and are not neces-
  38. (510) 422-0259         Livermore CA  94550   \\/Amiga\  sarily those of LLNL.
  39.