[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: Input of User-Defined types Up: Input/Output Previous: Stream Iterators

Output of User-Defined types

One way to do this is by overloading the stream insertion operator. The following defines how complex numbers should be printed out -

ostream& operator<<(ostream&s, complex z) // returns ostream& so can be chained
{
  return s << '(' << z.real() << ',' << z.imag() << ')';
}



Tim Love
2001-07-05