title: fstream::close() doesn't close file
body: <p>I have a program that reads a set of files, closes them, and then attempt to delete them.</p>
  
  <p>Sometimes (not always, but pretty often) the delete fails with 'sharing violation' error.</p>
  
  <p>Using sysinternals process monitor I saw that in these cases the close operation wasn't reflected in the process monitor.</p>
  
  <p>It appears that sometimes the close system call is skipped for no apparent reason, and without any exception.</p>
  
  <p>This is happening on a windows 7 64bit machine using visual studio 2010.</p>
  
  <p>Code sample;</p>
  
  <pre><code>void readFile(string file)
  {
    ifstream stream(file);
    string line;
    while(getline(stream, line))
    {
      cout &lt;&lt; line &lt;&lt; endl:
    }
    stream.close(); // this is redundant
  }
  </code></pre>
  
  <p>// calling code:</p>
  
  <pre><code>readFile(file);
  if(remove(file.c_str()) != 0)
  {
    cout &lt;&lt; "file deletion failed" &lt;&lt; endl;
  }
  </code></pre>