Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>streams with assignment</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Streams with Assignment

   The streams already discussed have had assignment operations explicitly
   excluded by being given a private copy constructor and operator=. This is
   because it is not clear what constitutes appropriate assignment behavior
   for streams.

   It has been the practice, however, to write code like:

   if (argc) > 1) {
       // file name supplied as source

       ifstream *ifp = new ifstream(argv[1]);
       cin = *ifp;
   }

   Here, if a filename was provided as a source of input, then an istream
   was  constructed using the file, and this istream was assigned to cin.
   The rest of the program simply assumed that input came from the  standard
   input.

   Classes that support assignment are defined to support code which uses
   this technique, and the C++ standard streams cin, cout, cerr (and where
   applicable) clog, are instances of stream classes of this sort.

   The additional public interfaces provided by these classes are as
   follows:

   class istream_withassign : public istream {
   public:
       istream_withassign();
       istream_withassign(streambuf *);

       ~istream_withassign();
       istream_withassign &operator=(istream &);
       istream_withassign &operator=(streambuf *);
   };

   class ostream_withassign : public ostream {
   public:
       ostream_withassign();
       ostream_withassign(streambuf *);
       ~ostream_withassign();
       ostream_withassign &operator=(ostream &);
       ostream_withassign &operator=(streambuf *);
   };

   class iostream_withassign : public iostream {
   public:
       iostream_withassign();
       iostream_withassign(streambuf *);
       ~iostream_withassign();
       iostream_withassign &operator=(ios &);

       iostream_withassign &operator=(streambuf *);
   };





Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson