A.3. IOStream Examples

This section presents several longer examples of the IOStream library. In “Overloading Streams” on page 324, we demonstrate overloading operator<<() and operator>>() for String objects. Let's do this for class Hue, a structure that stores and manipulates composite objects.

Hue

For simplicity, we've made Hue a structure with no constructor and all public data members. Hue objects consists of a character array, an integer, and a float. The main behavior we've given Hue objects is stream input and output by overloading operator<<() and operator>>(). Here is header file Hue.h.

Listing A.5. Hue structure definition
 #ifndef HUEH #define HUEH // Hue.h - Hue data type #include <iostream.h> #include <iomanip.h> struct Hue { char ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.