title: Why include both <iostream> and <fstream>
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2451681/why-do-i-need-to-include-both-the-iostream-and-fstream-headers-to-open-a-file">Why do I need to include both the iostream and fstream headers to open a file</a>  </p>
  </blockquote>
  
  
  
  <p>I wrote this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
     std::ofstream file_out("file.txt");
     file_out.close();
  
     return 0;
  }
  </code></pre>
  
  <p><code>std::ofstream</code> is defined in <code>&lt;iostream&gt;</code>, but compiling this code I obtain the following error:</p>
  
  <pre><code>error: variable 'std::ofstream file_out' has initializer but incomplete type
  </code></pre>
  
  <p>I discovered that if I also include <code>&lt;fstream&gt;</code> the error disappears and the code compiles. Why have I to include <code>&lt;fstream&gt;</code> if <code>std::ofstream</code> is included in <code>&lt;iostream&gt;</code>?</p>