title: What is the difference between flush() and sync() in regard to fstream buffers?
body: <p>I was reading the <a href="http://www.cplusplus.com/doc/tutorial/files/" rel="noreferrer">cplusplus.com tutorial on I/O</a>. At the end, it says fstream buffers are synchronized with the file on disc</p>
  <blockquote>
  <p><strong>Explicitly, with manipulators:</strong> When certain manipulators are used on
  streams, an explicit synchronization takes place. These manipulators
  are: flush and endl.</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p><strong>Explicitly, with member function sync():</strong> Calling
  stream's member function sync(), which takes no parameters, causes an
  immediate synchronization. This function returns an int value equal to
  -1 if the stream has no associated buffer or in case of failure. Otherwise (if the stream buffer was successfully synchronized) it
  returns 0.</p>
  </blockquote>
  <p>in addition to a few other implicit cases ( such as destruction and stream.close() )</p>
  <h2>What is the difference between calling fstream::flush() and fstream::sync()? endl?</h2>
  <p>In my code, I've always used flush().</p>
  <p>Documentation on std::flush():</p>
  <blockquote>
  <p><strong>Flush stream buffer</strong></p>
  <p>Synchronizes the buffer associated with the stream
  to its controlled output sequence. This effectively means that all
  unwritten characters in the buffer are written to its controlled
  output sequence as soon as possible (&quot;flushed&quot;).</p>
  </blockquote>
  <p>Documentation on std::streambuf::sync():</p>
  <blockquote>
  <p><strong>Synchronize input buffer with source of characters</strong></p>
  <p>It is called to synchronize the stream buffer with the controlled sequence (like the file in the case of file streams). The public member function pubsync calls this protected member function to perform this action.</p>
  </blockquote>
  <p>Forgive me if this is a newbie question; I am a noob.</p>