Input/Output Operators

The C++ standard library overloads the input operator >> and the output operator << for all built-in classes. Obviously, these operators do not know anything about programmer-defined classes. This is why when you need to input or output object data, you have to do this individually for each data member of the object.

It would be nice to overload the input/output operators for programmer-defined classes as well. Encapsulating these operations in overloaded operators would contribute to streamlining the client code, to eliminating low-level details of data management from the client code, and to pushing responsibility from client code to server classes.

Overloading operator >>

Consider, for example, class String from

Get Core C++ A Software Engineering Approach 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.