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++ Language Reference - streams: output functions http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Streams: Output Functions
   The  left shift operator is overloaded for each built in  type,  where
   there would be an ambiguity if no function with arguments that matched
   exactly  were  available. Most of these implementations  are  trivial,
   they  only require explicit casting. These are implemented  inline  so
   that there is no penalty in efficiency for the type-safe approach.

   Each  of  these functions returns an ostream reference, so  that  left
   shifts can be stacked, thus:
   cout << x;

   evaluates to a reference to an ostream. We can send more output to it:
   (cout << x) << y;

   The  associativity  of  left  shift means  that  the  parentheses  are
   unnecessary:

   cout << x << y;

   produces the required effect.

   There  are some lower precedence operators and you should remember  to
   parenthesize these:

   cout << "but x & y = " << (x & y) << "\n";

   Function  ostream::put  is  provided to  maintain  compatibility  with
   previous versions of C++, in which the use of the left shift  operator
   would result in the output of the integer value of a character.
   cout << 'A';   // prints 65 in older versions
                  // of C++
   cout.put('A'); // prints A
   cout << 'A';   // prints A in V2.0

   The  operation  of ostream::put and of ostream::operator<<  with  char
   arguments is now identical.


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