User-defined Data Types
If you overload the input and output operators, your data type behaves like a built-in data type.
For overloading the input and output operators you have to keep a few rules in mind:
- To support the chaining of input and output operations you have to get and return the input and output streams by non-constant reference.
- To access the private members of the class, the input and output operators have to be friends of your data type.
- The input operator
>>
takes its data type as a non-constant reference. - The output operator
<<
takes its data type as a constant reference.