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>output - class ostream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Output - Class ostream

   In many C++ publications the first piece of the language presented is the
   traditional "Hello World" program:

       #include <iostream.hpp>
       #include <stdlib.h>

       int main()
       {
           cout << "Hello world\n";
           return EXIT_SUCCESS;
       }

   The overloading of the left shift operator that allows this simple
   notation is provided by class ostream. This deals with output of the
   built-in types, and is designed to make implementation of output for user
   defined types simple and type-safe.

   The multiple overloads of the operator<< function are known as inserters,
   that is they insert representations of types into the output stream. It
   is the intention of the IOStream system that given:

       class T;        // T is a type, built in or user defined
       ostream s;
       T x;

   Then:

       s << x;

   is either a compilation error, or will insert a proper representation of
   x in the output stream.

   This is to be contrasted with the facilities available in C, where for
   instance:

       enum dummy { first, second };
       printf("%ld, %ld\n", first, second);

   will compile, but may print garbage.

   The ostream class is derived from class ios, so all the functions listed
   for class ios can be called for an ostream object.

   The ostream class is defined in the IOstreams header file iostream.hpp.
   Its public interface is as follows:

   class ostream {
   public:
   // Constructor/ destructor
       ostream(streambuf *);
       virtual ~ostream();

   //  Functions to simplify user defined inserters
       int opfx();
       void osfx();

   // Overloads of <<,  these are called "Inserters"
       ostream &operator<<(const char*);
       ostream &operator<<(const signed char*);
       ostream &operator<<(const unsigned char*);

       ostream &operator<<(char c);
       ostream &operator<<(signed char);
       ostream &operator<<(short);
       ostream &operator<<(int);
       ostream &operator<<(long);
       ostream &operator<<(unsigned char);
       ostream &operator<<(unsigned short);
       ostream &operator<<(unsigned int);
       ostream &operator<<(unsigned long);
       ostream &operator<<(float);
       ostream &operator<<(double);
       ostream &operator<<(void *);
       ostream &operator<<(streambuf *);
       ostream &operator<<(ostream &(*)(ostream &));
       ostream &operator<<(ios &(*)(ios &));

   // Unformatted output functions
       ostream &put(char c);
       ostream &write(const void *data, size_t size);
       size_t pcount();

   // Synchronize the output device with what has
   // been dispatched
       ostream &flush();

   // Seek and tell functions for file like streams
       ostream &seekp(streampos position);
       ostream &seekp(streamoff offset, seek_dir direction);
       streampos tellp();
   };

   All functions described here require the inclusion of iostream.hpp or
   some header file that itself includes iostream.hpp.





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