Difficulty: Easy
Correct Answer: fstream.h
Explanation:
Introduction / Context:
C++ uses a standard library of stream classes for console and file I/O. While std::cin and std::cout come from one header, file streams (for reading from and writing to files) come from another. Knowing the correct header improves portability and prevents compilation errors when working with files.
Given Data / Assumptions:
Concept / Approach:
File stream classes std::ifstream, std::ofstream, and std::fstream are declared in the header historically called fstream.h (modern C++ uses
Step-by-Step Solution:
Identify the classes to be used: ifstream/ofstream/fstream for files.Recall the corresponding header: fstream.h (or the modern
Verification / Alternative check:
Create a simple program that opens a file with std::ifstream. Including fstream.h (or
Why Other Options Are Wrong:
Common Pitfalls:
Mixing legacy .h headers with modern headers. Prefer
Final Answer:
fstream.h.
Discussion & Comments