Chapter Summary
C++ uses library classes to handle stream-oriented input and output:
• The iostream
classes handle IO to console
• The fstream
classes handle IO to named files
• The stringstream
classes do IO to in-memory string
s
The fstream
and stringstream
classes are related by inheritance to the iostream
classes. The input classes inherit from istream
and the output classes from ostream
. Thus, operations that can be performed on an istream
object can also be performed on either an ifstream
or an istringstream
. Similarly for the output classes, which inherit from ostream
.
Each IO object maintains a set of condition states that indicate whether IO can be done through this object. If an error is encountered—such as hitting end-of-file on an ...
Get C++ Primer, Fifth Edition 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.