home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16698 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  2.1 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!lll-winken!taurus!taygeta.oc.nps.navy.mil!skip
  2. From: skip@taygeta.oc.nps.navy.mil (Skip Carter)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Just what is so great about streams?
  5. Message-ID: <7011@taurus.cs.nps.navy.mil>
  6. Date: 18 Nov 92 23:26:35 GMT
  7. References: <1992Nov12.061942.16473@nuscc.nus.sg> <TMB.92Nov13102951@arolla.idiap.ch> <6994@taurus.cs.nps.navy.mil> <1992Nov18.134551.5782@bcrka451.bnr.ca>
  8. Sender: news@taurus.cs.nps.navy.mil
  9. Reply-To: skip@taygeta.oc.nps.navy.mil (Skip Carter)
  10. Lines: 45
  11.  
  12. In article <1992Nov18.134551.5782@bcrka451.bnr.ca>, sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
  13. |> In article <6994@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes:
  14. |> >
  15. | >>         ...............
  16. |> 
  17. |> [class TimeStamp]
  18. |> >         friend ostream& operator<<(ostream& os, const TimeStamp& t);
  19. |> >};
  20. |> >
  21. |> >class Comment : public ostrstream                   // write a comment to a file, with user defined start and end
  22. |> >{                                                                             //  comment sequences
  23. |> >
  24. |> >    Now the TimeStamp class can write a comment WITH NO CHANGES MADE TO
  25. |> >    THE TIMESTAMP CLASS.
  26. |> >
  27. |> >    Comment fout(...);
  28. |> >
  29. |> >    fout << TimeStamp();
  30. |> >
  31. |> >
  32. |> >    In fact, TimeStamp can properly write to any class that is ultimately derived from ostream.
  33. |> >
  34. |> 
  35. |> What about     fout << t << t << endl;   
  36. |> The wrong operator<<() will be called for the second output unless you provide
  37. |> the appropriate friend function for TimeStamp, no?
  38. |> 
  39.  
  40.     There is no problem at all with      fout << t1<< t2 << endl;
  41.     Since  the evaluation order is:
  42.     first,
  43.         fout << t1;    
  44.  
  45.     which returns a reference to fout which  is then used in the operation,
  46.  
  47.         (reference to fout) << t2;
  48.  
  49.     which again returns a reference to fout, which finally gets the    endl
  50.  
  51.  
  52. -- 
  53.  Everett (Skip) Carter             Phone:  408-646-3318 FAX: 408-646-2712
  54.  Naval Postgraduate School         INTERNET: skip@taygeta.oc.nps.navy.mil
  55.  Dept. of Oceanography, Code OC/CR  UUCP:     ...!uunet!taygeta!skip
  56.  Monterey, CA. 93943               TELEMAIL: s.carter/omnet
  57.