home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!lll-winken!taurus!taygeta.oc.nps.navy.mil!skip
- From: skip@taygeta.oc.nps.navy.mil (Skip Carter)
- Newsgroups: comp.lang.c++
- Subject: Re: Just what is so great about streams?
- Message-ID: <7011@taurus.cs.nps.navy.mil>
- Date: 18 Nov 92 23:26:35 GMT
- References: <1992Nov12.061942.16473@nuscc.nus.sg> <TMB.92Nov13102951@arolla.idiap.ch> <6994@taurus.cs.nps.navy.mil> <1992Nov18.134551.5782@bcrka451.bnr.ca>
- Sender: news@taurus.cs.nps.navy.mil
- Reply-To: skip@taygeta.oc.nps.navy.mil (Skip Carter)
- Lines: 45
-
- In article <1992Nov18.134551.5782@bcrka451.bnr.ca>, sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
- |> In article <6994@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes:
- |> >
- | >> ...............
- |>
- |> [class TimeStamp]
- |> > friend ostream& operator<<(ostream& os, const TimeStamp& t);
- |> >};
- |> >
- |> >class Comment : public ostrstream // write a comment to a file, with user defined start and end
- |> >{ // comment sequences
- |> >
- |> > Now the TimeStamp class can write a comment WITH NO CHANGES MADE TO
- |> > THE TIMESTAMP CLASS.
- |> >
- |> > Comment fout(...);
- |> >
- |> > fout << TimeStamp();
- |> >
- |> >
- |> > In fact, TimeStamp can properly write to any class that is ultimately derived from ostream.
- |> >
- |>
- |> What about fout << t << t << endl;
- |> The wrong operator<<() will be called for the second output unless you provide
- |> the appropriate friend function for TimeStamp, no?
- |>
-
- There is no problem at all with fout << t1<< t2 << endl;
- Since the evaluation order is:
- first,
- fout << t1;
-
- which returns a reference to fout which is then used in the operation,
-
- (reference to fout) << t2;
-
- which again returns a reference to fout, which finally gets the endl
-
-
- --
- Everett (Skip) Carter Phone: 408-646-3318 FAX: 408-646-2712
- Naval Postgraduate School INTERNET: skip@taygeta.oc.nps.navy.mil
- Dept. of Oceanography, Code OC/CR UUCP: ...!uunet!taygeta!skip
- Monterey, CA. 93943 TELEMAIL: s.carter/omnet
-