- Asked 4/10
- 2074 Chaitra · 2 marks
- 2072 Chaitra · 3 marks
- 2072 Kartik · 3 marks
- 2068 Baisakh · 2 marks
Stream class hierarchy
Short answer
The stream hierarchy has ios as the base with formatting and state flags. istream (input, cin) and ostream (output, cout, cerr) derive from it, and iostream inherits both. File streams ifstream, ofstream, fstream extend istream/ostream/iostream, while streambuf manages the buffer.
Discuss about stream class hierarchy.
A stream is a flow of data between a program and a device (keyboard, screen, file). C++ stream classes are arranged in a hierarchy, declared in <iostream>, <fstream>, etc.
ios_base
|
ios
________|________
| |
istream ostream
| \ / |
| \_iostream_/ |
ifstream | ofstream
|
fstream
- ios – base class; holds format flags, state flags (
eofbit,failbit,badbit) and a pointer tostreambuf. - istream – input class; provides
>>,get(),getline(),read(). Objectcinbelongs to it. - ostream – output class; provides
<<,put(),write(). Objectscout,cerr,clogbelong to it. - iostream – derives from both
istreamandostreamfor input and output on one stream. - ifstream, ofstream, fstream – file input, output and input/output classes (
<fstream>). - streambuf – manages the buffer between the program and the device.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Stream and file stream classes · Object Oriented Programming, chapter 8
- File stream; student binary file program · Object Oriented Programming, chapter 8
- Time class: +, <= and << overloading · Object Oriented Programming, chapter 5
- Exception class hierarchy from Throwable · Object Oriented Analysis and Design, chapter 4