summaryrefslogtreecommitdiff
path: root/devdocs/c/io%2Ffflush.html
blob: b3ba871674eca9b6f2930bed87ce7ead8f76ac45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    <h1 id="firstHeading" class="firstHeading">fflush</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;stdio.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td class="t-dcl-nopad"> <pre data-language="c">int fflush( FILE *stream );</pre>
</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr>  </table> <p>For output streams (and for update streams on which the last operation was output), writes any unwritten data from the <code>stream</code>'s buffer to the associated output device.</p>
<p>For input streams (and for update streams on which the last operation was input), the behavior is undefined.</p>
<p>If <code>stream</code> is a null pointer, all open output streams are flushed, including the ones manipulated within library packages or otherwise not directly accessible to the program.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> stream </td> <td> - </td> <td> the file stream to write out </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>Returns zero on success. Otherwise <code><a href="../io" title="c/io">EOF</a></code> is returned and the error indicator of the file stream is set.</p>
<h3 id="Notes"> Notes</h3> <p>POSIX <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html">extends the specification of fflush</a> by defining its effects on an input stream, as long as that stream represents a file or another seekable device: in that case the POSIX file pointer is repositioned to match the C stream pointer (which effectively undoes any read buffering) and the effects of any <code><a href="ungetc" title="c/io/ungetc">ungetc</a></code> or <code><a href="ungetwc" title="c/io/ungetwc">ungetwc</a></code> that weren't yet read back from the stream are discarded.</p>
<p>Microsoft also extends the specification of fflush by defining its effects on an input stream: in Visual Studio 2013 and prior, it <a rel="nofollow" class="external text" href="https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/9yky46tz(v=vs.120)">discarded the input buffer</a>, in Visual Studio 2015 and newer, it <a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/9yky46tz.aspx">has no effect, buffers are retained</a>.</p>
<h3 id="References"> References</h3>  <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.21.5.2 The fflush function (p: 305) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.19.5.2 The fflush function (p: 270-271) </li></ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul><li> 4.9.5.2 The fflush function </li></ul>
</ul>         <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="fopen" title="c/io/fopen"> <span class="t-lines"><span>fopen</span><span>fopen_s</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> opens a file <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="fclose" title="c/io/fclose"> <span class="t-lines"><span>fclose</span></span></a></div> </td> <td> closes a file <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/io/c/fflush" title="cpp/io/c/fflush">C++ documentation</a></span> for <code>fflush</code> </td>
</tr> </table>            <div class="_attribution">
  <p class="_attribution-p">
    &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
    <a href="https://en.cppreference.com/w/c/io/fflush" class="_attribution-link">https://en.cppreference.com/w/c/io/fflush</a>
  </p>
</div>