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