Overloading the >> Operator for Your Own Classes

Input streams use the extraction (>>) operator for the standard types. You can write similar extraction operators for your own types, but, as with all extraction operations, success depends on the precise use of white space.

Below is an example of an extraction operator for the Date class that was presented in Example 14 on pages 380-381:

istream& operator>> ( istream& is, Date& dt )

{

is >> dt.mo >> dt.da >> dt.yr;

return is;

}

A more complete extraction operator might check the validity of the date that was entered.