Introduction / Context:
C++ uses a rich stream abstraction for input and output. Different stream classes handle reading and writing, sometimes in combination. Grasping which streams are for input and which are for output is essential when selecting the appropriate headers, objects, and operators in your program.
Given Data / Assumptions:
- Standard library components such as std::istream, std::ostream, and std::iostream.
- Console streams (std::cin, std::cout, std::cerr) and file streams (std::ifstream, std::ofstream, std::fstream).
- Operator usage: >> extracts (input) and << inserts (output).
Concept / Approach:
- Input-only streams (e.g., std::istream, std::ifstream) support extraction operations.
- Output-only streams (e.g., std::ostream, std::ofstream) support insertion operations.
- Bidirectional streams (e.g., std::iostream, std::fstream) can perform both, depending on open modes.
Step-by-Step Explanation:
Identify class roles: istream → input, ostream → output, iostream → both.Map to common objects: std::cin is an istream; std::cout/std::cerr are ostreams.File streams mirror this: ifstream (in), ofstream (out), fstream (in/out).
Verification / Alternative check:
Compile a small snippet using ifstream to read and ofstream to write; the types enforce directionality through available operations and open modes.
Why Other Options Are Wrong:
- False: Incorrect because standard stream classes are explicitly separated by direction, with some combined classes supporting both.
Common Pitfalls:
- Attempting to write to an ifstream or read from an ofstream without opening modes or using the proper class.
- Confusing line-buffered behavior of std::cout with flushing requirements.
Final Answer:
True
Discussion & Comments