title: Why do I need to include both the iostream and fstream headers to open a file
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main () {
    ofstream myfile;
    myfile.open ("test.txt");
    return 0;
  }
  </code></pre>
  
  <p>fstream is derived from iostream, why should we include both in the code above?</p>
  
  <p>I removed fstream, however, there is an error with ofstream. My question is ofstream is derived from ostream, why fstream is needed to make it compile?</p>