C++ headers: which header provides the declarations for both cin and cout (per classic options listed)?
-
Aistream.h
-
Bostream.h
-
Ciomanip.h
-
Diostream.h
Answer
Correct Answer: iostream.h
Explanation
Introduction / Context:Modern C++ uses header names without the .h suffix, such as . However, many legacy multiple-choice questions still cite pre-standard headers. Among the given choices, one classic header historically declared both cin and cout together.
Given Data / Assumptions:
- We accept the question’s legacy-style options.
cinandcoutare standard input/output stream objects.- We focus on the header that includes both in one unit.
Concept / Approach:
Historically, the header <iostream.h> (pre-Standard C++) declared stream classes and the global objects cin, cout, cerr, and clog. Modern C++ replaces it with <iostream> in namespace std. Separate headers like <istream.h> and <ostream.h> were compiler-specific and are not part of the current standard. Given the provided choices, the correct legacy answer is iostream.h.
Step-by-Step Solution:
1) Identify which option historically brings in both input and output streams. 2) Chooseiostream.h, the combined header. 3) Note that modern code should prefer #include <iostream> and std::cout/std::cin. 4) Remember that manipulators like <iomanip> are separate in both eras. Verification / Alternative check:
Compiling legacy examples against old compilers required <iostream.h>. On conforming modern compilers, <iostream.h> is absent; use <iostream> instead (but that is not among the options here).
Why Other Options Are Wrong:
istream.h and ostream.h: non-standard, often partial; not both together.
iomanip.h: for formatting manipulators, not for defining cin/cout.
Common Pitfalls:
- Memorizing legacy headers without understanding that modern code uses
<iostream>(no .h) and namespacestd.
Final Answer:
iostream.h