title: Can write to a file fail in the middle of a flush operation
body: <p>I am writing contents to a csv file <strong><em>one line at a time</em></strong> and was wondering if write can fail in the middle of a flush operation</p>
  
  <p><strong>My purpose is to understand the different ways a write to a file can be corrupted</strong></p>
  
  <p>Assume the following is the structure of the csv file after a successful write to it</p>
  
  <pre><code> 1,1001210212
   2,8941321654
   6,845646
   17,564968896
  </code></pre>
  
  <p>Say an error occurs while flushing the 3rd line to file, could it result in the following form </p>
  
  <pre><code> 1,1001210212\n       //showing \n just for understanding purpose. Not actually visible as "\n" in the file
   2,8941321654\n 
   6,845
  </code></pre>
  
  <p>Or</p>
  
  <pre><code> 1,1001210212\n
   2,8941321654\n
  </code></pre>
  
  <p>or</p>
  
  <pre><code>1,1001210212\n
  2,8941321654\n
  6,845646\n              //Fails right after writing the line. Not sure if such an error is even possible
  </code></pre>
  
  <p>or</p>
  
  <pre><code>1,1001210212\n
  2,8941321654\n
  6,845646
  </code></pre>
  
  <p><strong>My code if needed</strong>   </p>
  
  <blockquote>
    <p>something.cpp</p>
  </blockquote>
  
  <pre><code>hash_map&lt;int, unsigned long long&gt; tableData;
  
  //assume hash map is populated here
  
  string outFile = "C:\outFile.csv";
  FILE *fout = NULL;
  
  if (outFile.length())
  {
      fout = fopen(outFile.c_str(), "a");
  }   
  if (fout != NULL)
  {
      for (vector&lt;uint32_t&gt;::iterator keyValue = keys.begin(); 
      keyValue != keys.end(); ++keyValue)
      {
          fprintf(fout,"%d,",*keyValue);
          fprintf(fout,"%lld\n",tableData[*keyValue]); 
          fflush(fout); 
      }
  }
  </code></pre>