Mail Archives: djgpp/1998/02/05/03:00:23
On Wed, 4 Feb 1998 21:14:58 -0500 in comp.os.msdos.djgpp DeHackEd
<Not DOT given AT out> wrote:
: And the second error occurs because the command >> is the binary shift command
: or the istream receive operator. That one always makes me wonder - isn't cout <<
: "Hello world!"; usually a binary shift of "cout" left a few thousand places
: (because the pointer will probably in the range of 2048+ at least...), but then
: C++ would considder it a re-write of the default commands. Odd but unusual way
: of using the language to your advantage.
As far as I understand this (and I tend to avoid C++ for various
reasons) the iostreams work through operator overloading. `<<' and
`>>' aren't assignment operators as you imply -- they're normally
simple arithmetic operators (i.e. they return a value, but don't
assign it to anything). However, the action of these operators on a
class (cout and cin are instances of classes) can be overloaded (as
can many operators' actions), i.e. replaced with a method in the
class. These methods for iostreams happen to read from input streams
and write to output streams.
There's nothing particularly special about the choice of `<<' and
`>>'; many other (binary) operators would have done, e.g.:
cout + "Hello world!" + endl;
cin * a;
if `+' and `*' had been overloaded instead.
As I said, this is just `AFAIK' and I'm not a great C++ user -- take
it with a pinch of salt, and UTSL if you're really curious (it ought
to be in iostream.h).
--
george DOT foot AT merton DOT oxford DOT ac DOT uk
Remember what happened to the dinosaurs.
- Raw text -