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

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
  void rewind( FILE *stream );</pre>  <p>The function rewind() moves the file position indicator to the  beginning of the specified <em>stream</em>, also clearing the error  and <strong>EOF</strong> flags associated with that stream.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fseek.html">fseek</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    scanf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int scanf( const char *format, ... );</pre>  <p>The scanf() function reads input from <strong>stdin</strong>,  according to the given <em>format</em>, and stores the data in the  other arguments. It works a lot like <a href=  "printf.html">printf</a>(). The <em>format</em> string consists of  control characters, whitespace characters, and non-whitespace  characters. The control characters are preceded by a % sign, and are  as follows:</p>  <table class="code-table">    <tr>      <th class="code-table-th">Control Character</th>      <th class="code-table-th">Explanation</th>    </tr>    <tr>      <td class="code-table-td">%c</td>      <td class="code-table-td">a single character</td>    </tr>    <tr>      <td class="code-table-td">%d</td>      <td class="code-table-td">a decimal integer</td>    </tr>    <tr>      <td class="code-table-td">%i</td>      <td class="code-table-td">an integer</td>    </tr>    <tr>      <td class="code-table-td">%e, %f, %g</td>      <td class="code-table-td">a floating-point number</td>    </tr>    <tr>      <td class="code-table-td">%o</td>      <td class="code-table-td">an octal number</td>    </tr>    <tr>      <td class="code-table-td">%s</td>      <td class="code-table-td">a string</td>    </tr>    <tr>      <td class="code-table-td">%x</td>      <td class="code-table-td">a hexadecimal number</td>    </tr>    <tr>      <td class="code-table-td">%p</td>      <td class="code-table-td">a pointer</td>    </tr>    <tr>      <td class="code-table-td">%n</td>      <td class="code-table-td">an integer equal to the number of      characters read so far</td>    </tr>    <tr>      <td class="code-table-td">%u</td>      <td class="code-table-td">an unsigned integer</td>    </tr>    <tr>      <td class="code-table-td">%[]</td>      <td class="code-table-td">a set of characters</td>    </tr>    <tr>      <td class="code-table-td">%% a percent sign</td>    </tr>  </table>  <p>scanf() reads the input, matching the characters from format. When  a control character is read, it puts the value in the next variable.  Whitespace (tabs, spaces, etc) are skipped. Non-whitespace characters  are matched to the input, then discarded. If a number comes between  the % sign and the control character, then only that many characters  will be converted into the variable. If scanf() encounters a set of  characters, denoted by the %[] control character, then any characters  found within the brackets are read into the variable. The return  value of scanf() is the number of variables that were successfully  assigned values, or <strong>EOF</strong> if there is an error.</p>  <div class="related-examples-format">    Example code:  </div>  <div class="related-examples">    <p>This code snippet repeatedly uses scanf() to read integers and    floats from the user. Note that the variable arguments to scanf()    are passed in by reference, as denoted by the ampersand (&amp;)    preceding each variable:</p>    <pre class="example-code"> int i; float f;                while( 1 ) {   printf( &quot;Enter an integer: &quot; );   scanf( &quot;%d&quot;, &amp;i );                printf( &quot;Enter a float: &quot; );   scanf( &quot;%f&quot;, &amp;f );                printf( &quot;You entered %d and then %f\n&quot;, i, f ); }              </pre>  </div>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fgets.html">fgets</a><br>    <a href="fscanf.html">fscanf</a><br>    <a href="printf.html">printf</a><br>    <a href="sscanf.html">sscanf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    setbuf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  void setbuf( FILE *stream, char *buffer );</pre>  <p>The setbuf() function sets <em>stream</em> to use <em>buffer</em>,  or, if <em>buffer</em> is null, turns off buffering. If a  non-standard buffer size is used, it should be BUFSIZ characters  long.</p>  <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="setvbuf.html">setvbuf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    setvbuf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int setvbuf( FILE *stream, char *buffer, int mode, size_t size );</pre>  <p>The function setvbuf() sets the buffer for <em>stream</em> to be  <em>buffer</em>, with a size of <em>size</em>. <em>mode</em> can  be:</p>  <ul>    <li>_IOFBF, which indicates full buffering</li>    <li>_IOLBF, which means line buffering</li>    <li>_IONBF, which means no buffering</li>  </ul>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="setbuf.html">setbuf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    sprintf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int sprintf( char *buffer, const char *format, ... );</pre>  <p>The sprintf() function is just like <a href=  "printf.html">printf</a>(), except that the output is sent to  <em>buffer</em>. The return value is the number of characters  written. For example:</p>  <pre class="example-code">   char string[50];   int file_number = 0;            sprintf( string, &quot;file.%d&quot;, file_number );   file_number++;   output_file = fopen( string, &quot;w&quot; );                </pre>  <p>Note that sprintf() does the opposite of a function like <a  href="../stdstring/atoi.html">atoi</a>() -- where <a href=  "../stdstring/atoi.html">atoi</a>() converts a string into a number,  sprintf() can be used to convert a number into a string.</p>  <p>For example, the following code uses sprintf() to convert an  integer into a string of characters:</p>  <pre class="example-code">   char result[100];   int num = 24;   sprintf( result, &quot;%d&quot;, num );              </pre>  <p>This code is similar, except that it converts a floating-point  number into an array of characters:</p>  <pre class="example-code">   char result[100];   float fnum = 3.14159;   sprintf( result, &quot;%f&quot;, fnum );</pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    (Standard C String and Character) <a href=    "../stdstring/atof.html">atof</a><br>    (Standard C String and Character) <a href=    "../stdstring/atoi.html">atoi</a><br>    (Standard C String and Character) <a href=    "../stdstring/atol.html">atol</a><br>    <a href="fprintf.html">fprintf</a><br>    <a href="printf.html">printf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    sscanf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int sscanf( const char *buffer, const char *format, ... );</pre>  <p>The function sscanf() is just like <a href=  "scanf.html">scanf</a>(), except that the input is read from  <em>buffer</em>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fscanf.html">fscanf</a><br>    <a href="scanf.html">scanf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    tmpfile  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  FILE *tmpfile( void );</pre>  <p>The function tempfile() opens a temporary file with an unique  filename and returns a pointer to that file. If there is an error,  null is returned.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="tmpnam.html">tmpnam</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    tmpnam  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  char *tmpnam( char *name );</pre>  <p>The tmpnam() function creates an unique filename and stores it in  <em>name</em>. tmpnam() can be called up to <strong>TMP_MAX</strong>  times.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="tmpfile.html">tmpfile</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    ungetc  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int ungetc( int ch, FILE *stream );</pre>  <p>The function ungetc() puts the character <em>ch</em> back in  <em>stream</em>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="getc.html">getc</a><br>    (C++ I/O) <a href="../cppio/putback.html">putback</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    vprintf, vfprintf, and vsprintf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdarg.h&gt;  #include &lt;stdio.h&gt;  int vprintf( char *format, <strong>va_list</strong> arg_ptr );  int vfprintf( FILE *stream, const char *format, <strong>va_list</strong> arg_ptr );  int vsprintf( char *buffer, char *format, <strong>va_list</strong> arg_ptr );</pre>  <p>These functions are very much like <a href=  "printf.html">printf</a>(), <a href="fprintf.html">fprintf</a>(), and  <a href="sprintf.html">sprintf</a>(). The difference is that the  argument list is a pointer to a list of arguments.  <strong>va_list</strong> is defined in stdarg.h, and is also used by  (Other Standard C Functions) <a href=  "../stdother/va_arg.html">va_arg</a>(). For example:</p>  <pre class="example-code">   void error( char *fmt, ... ) {     <strong>va_list</strong> args;     va_start( args, fmt );     fprintf( stderr, &quot;Error: &quot; );     vfprintf( stderr, fmt, args );     fprintf( stderr, &quot;\n&quot; );     va_end( args );     exit( 1 );   }            </pre>  </div>  </td>    </tr>  </table></body></html><hr></body></html>

⌨️ 快捷键说明

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