⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta name="generator" content=  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">  <title>Standard C I/O</title>  <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table>  <tr>  <td>  <div class="body-content">  <div class="header-box">    <a href="../index.html">cppreference.com</a> &gt; <a href=    "index.html">Standard C I/O</a>  </div>  <div class="name-format">    clearerr  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  void clearerr( FILE *stream );</pre>  <p>The clearerr function resets the error flags and  <strong>EOF</strong> indicator for the given <em>stream</em>. When an  error occurs, you can use <a href="perror.html">perror</a>() to  figure out which error actually occurred.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="feof.html">feof</a><br>    <a href="ferror.html">ferror</a><br>    <a href="perror.html">perror</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fclose  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int fclose( FILE *stream );  </pre>  <p>The function fclose() closes the given file stream, deallocating  any buffers associated with that stream. fclose() returns 0 upon  success, and <strong>EOF</strong> otherwise.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fflush.html">fflush</a><br>    <a href="fopen.html">fopen</a><br>    <a href="freopen.html">freopen</a><br>    <a href="setbuf.html">setbuf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    feof  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int feof( FILE *stream );  </pre>  <p>The function feof() returns a nonzero value if the end of the  given file <em>stream</em> has been reached.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="clearerr.html">clearerr</a><br>    <a href="ferror.html">ferror</a><br>    <a href="getc.html">getc</a><br>    <a href="perror.html">perror</a><br>    <a href="putc.html">putc</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    ferror  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int ferror( FILE *stream );</pre>  <p>The ferror() function looks for errors with <em>stream</em>,  returning zero if no errors have occured, and non-zero if there is an  error. In case of an error, use <a href="perror.html">perror</a>() to  determine which error has occured.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="clearerr.html">clearerr</a><br>    <a href="feof.html">feof</a><br>    <a href="perror.html">perror</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fflush  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int fflush( FILE *stream );</pre>  <p>If the given file <em>stream</em> is an output stream, then  fflush() causes the output buffer to be written to the file. If the  given <em>stream</em> is of the input type, then fflush() causes the  input buffer to be cleared. fflush() is useful when debugging, if a  program segfaults before it has a chance to write output to the  screen. Calling fflush( <strong>stdout</strong> ) directly after  debugging output will ensure that your output is displayed at the  correct time.</p>  <pre class="example-code">   printf( &quot;Before first call\n&quot; );   fflush( <strong>stdout</strong> );   shady_function();   printf( &quot;Before second call\n&quot; );   fflush( <strong>stdout</strong> );   dangerous_dereference();             </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fclose.html">fclose</a><br>    <a href="fopen.html">fopen</a><br>    <a href="fread.html">fread</a><br>    <a href="fwrite.html">fwrite</a><br>    <a href="getc.html">getc</a><br>    <a href="putc.html">putc</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fgetc  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int fgetc( FILE *stream );</pre>  <p>The fgetc() function returns the next character from  <em>stream</em>, or <strong>EOF</strong> if the end of file is  reached or if there is an error.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fopen.html">fopen</a><br>    <a href="fputc.html">fputc</a><br>    <a href="fread.html">fread</a><br>    <a href="fwrite.html">fwrite</a><br>    <a href="getc.html">getc</a><br>    <a href="getchar.html">getchar</a><br>    <a href="gets.html">gets</a><br>    <a href="putc.html">putc</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fgetpos  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int fgetpos( FILE *stream, fpos_t *position );</pre>  <p>The fgetpos() function stores the file position indicator of the  given file <em>stream</em> in the given <em>position</em> variable.  The position variable is of type fpos_t (which is defined in stdio.h)  and is an object that can hold every possible position in a FILE.  fgetpos() returns zero upon success, and a non-zero value upon  failure.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fseek.html">fseek</a><br>    <a href="fsetpos.html">fsetpos</a><br>    <a href="ftell.html">ftell</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fgets  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  char *fgets( char *str, int num, FILE *stream );</pre>  <p>The function fgets() reads up to <em>num</em> - 1 characters from  the given file <em>stream</em> and dumps them into <em>str</em>.  The string that fgets() produces is always  <strong>NULL</strong>-terminated.  fgets() will stop when it reaches  the end of a line, in which case <em>str</em> will contain that  newline character. Otherwise, fgets() will stop when it reaches  <em>num</em> - 1 characters or encounters the <strong>EOF</strong>  character.  fgets() returns <em>str</em> on success, and  <strong>NULL</strong> on an error.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fputs.html">fputs</a><br>    <a href="fscanf.html">fscanf</a><br>    <a href="gets.html">gets</a><br>    <a href="scanf.html">scanf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fopen  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  FILE *fopen( const char *fname, const char *mode );</pre>  <p>The fopen() function opens a file indicated by <em>fname</em> and  returns a stream associated with that file. If there is an error,  fopen() returns <strong>NULL</strong>. <em>mode</em> is used to  determine how the file will be treated (i.e. for input, output,  etc)</p>  <table class="code-table">    <tr>      <th class="code-table-th">Mode</th>      <th class="code-table-th">Meaning</th>    </tr>    <tr>      <td class="code-table-td">&quot;r&quot;</td>      <td class="code-table-td">Open a text file for reading</td>    </tr>    <tr>      <td class="code-table-td">&quot;w&quot;</td>      <td class="code-table-td">Create a text file for writing</td>    </tr>    <tr>      <td class="code-table-td">&quot;a&quot;</td>      <td class="code-table-td">Append to a text file</td>    </tr>    <tr>      <td class="code-table-td">&quot;rb&quot;</td>      <td class="code-table-td">Open a binary file for reading</td>    </tr>    <tr>      <td class="code-table-td">&quot;wb&quot;</td>      <td class="code-table-td">Create a binary file for writing</td>    </tr>    <tr>      <td class="code-table-td">&quot;ab&quot;</td>      <td class="code-table-td">Append to a binary file</td>    </tr>    <tr>      <td class="code-table-td">&quot;r+&quot;</td>      <td class="code-table-td">Open a text file for read/write</td>    </tr>    <tr>      <td class="code-table-td">&quot;w+&quot;</td>      <td class="code-table-td">Create a text file for read/write</td>    </tr>    <tr>      <td class="code-table-td">&quot;a+&quot;</td>      <td class="code-table-td">Open a text file for read/write</td>    </tr>    <tr>      <td class="code-table-td">&quot;rb+&quot;</td>      <td class="code-table-td">Open a binary file for read/write</td>    </tr>    <tr>      <td class="code-table-td">&quot;wb+&quot;</td>      <td class="code-table-td">Create a binary file for      read/write</td>    </tr>    <tr>      <td class="code-table-td">&quot;ab+&quot;</td>      <td class="code-table-td">Open a binary file for read/write</td>    </tr>  </table>  <p>An example:</p>  <pre class="example-code">   int ch;   FILE *input = fopen( &quot;stuff&quot;, &quot;r&quot; );   ch = getc( input );          </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fclose.html">fclose</a><br>    <a href="fflush.html">fflush</a><br>    <a href="fgetc.html">fgetc</a><br>    <a href="fputc.html">fputc</a><br>    <a href="fread.html">fread</a><br>    <a href="freopen.html">freopen</a><br>    <a href="fseek.html">fseek</a><br>    <a href="fwrite.html">fwrite</a><br>    <a href="getc.html">getc</a><br>    <a href="getchar.html">getchar</a><br>    <a href="setbuf.html">setbuf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    fprintf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int fprintf( FILE *stream, const char *format, ... );</pre>  <p>The fprintf() function sends information (the arguments) according  to the specified <em>format</em> to the file indicated by  <em>stream</em>. fprintf() works just like <a href=  "printf.html">printf</a>() as far as the format goes. The return  value of fprintf() is the number of characters outputted, or a  negative number if an error occurs. An example:</p>  <pre class="example-code">   char name[20] = &quot;Mary&quot;;   FILE *out;   out = fopen( &quot;output.txt&quot;, &quot;w&quot; );   if( out != <strong>NULL</strong> )     fprintf( out, &quot;Hello %s\n&quot;, name );              </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fputc.html">fputc</a><br>    <a href="fputs.html">fputs</a><br>    <a href="fscanf.html">fscanf</a><br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -