C++ headers: which header provides the declarations for both cin and cout (per classic options listed)?

Difficulty: Easy

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.
  • cin and cout are 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) Choose iostream.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 namespace std.


Final Answer:

iostream.h

More Questions from OOPS Concepts

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion