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

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
    <a href="puts.html">puts</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    perror  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  void perror( const char *str );</pre>  <p>The perror() function prints <em>str</em> and an  implementation-defined error message corresponding to the global  variable <em>errno</em>.  For example:</p>  <pre class="example-code">  char* input_filename = "not_found.txt";  FILE* input = fopen( input_filename, "r" );  if( input == NULL ) {    char error_msg[255];    sprintf( error_msg, "Error opening file '%s'", input_filename );    perror( error_msg );    exit( -1 );  }</pre>  <p>The the file called <em>not_found.txt</em> is not found, this  code will produce the following output:</p>  <pre class="example-output">  Error opening file 'not_found.txt': No such file or directory</pre>  <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="ferror.html">ferror</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    printf  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int printf( const char *format, ... );</pre>  <p>The printf() function prints output to <strong>stdout</strong>,  according to <em>format</em> and other arguments passed to printf().  The string <em>format</em> consists of two types of items -  characters that will be printed to the screen, and format commands  that define how the other arguments to printf() are displayed.  Basically, you specify a format string that has text in it, as well  as &quot;special&quot; characters that map to the other arguments of  printf(). For example, this code</p>  <pre class="example-code">   char name[20] = &quot;Bob&quot;;   int age = 21;   printf( &quot;Hello %s, you are %d years old\n&quot;, name, age );           </pre>  <p>displays the following output:</p>  <pre class="example-code">   Hello Bob, you are 21 years old              </pre>  <p>The %s means, &quot;insert the first argument, a string, right  here.&quot; The %d indicates that the second argument (an integer)  should be placed there. There are different %-codes for different  variable types, as well as options to limit the length of the  variables and whatnot.</p>  <table class="code-table">    <tr>      <th class="code-table-th">Code</th>      <th class="code-table-th">Format</th>    </tr>    <tr>      <td class="code-table-td">%c</td>      <td class="code-table-td">character</td>    </tr>    <tr>      <td class="code-table-td">%d</td>      <td class="code-table-td">signed integers</td>    </tr>    <tr>      <td class="code-table-td">%i</td>      <td class="code-table-td">signed integers</td>    </tr>    <tr>      <td class="code-table-td">%e</td>      <td class="code-table-td">scientific notation, with a lowercase      &quot;e&quot;</td>    </tr>    <tr>      <td class="code-table-td">%E</td>      <td class="code-table-td">scientific notation, with a uppercase      &quot;E&quot;</td>    </tr>    <tr>      <td class="code-table-td">%f</td>      <td class="code-table-td">floating point</td>    </tr>    <tr>      <td class="code-table-td">%g</td>      <td class="code-table-td">use %e or %f, whichever is shorter</td>    </tr>    <tr>      <td class="code-table-td">%G</td>      <td class="code-table-td">use %E or %f, whichever is shorter</td>    </tr>    <tr>      <td class="code-table-td">%o</td>      <td class="code-table-td">octal</td>    </tr>    <tr>      <td class="code-table-td">%s</td>      <td class="code-table-td">a string of characters</td>    </tr>    <tr>      <td class="code-table-td">%u</td>      <td class="code-table-td">unsigned integer</td>    </tr>    <tr>      <td class="code-table-td">%x</td>      <td class="code-table-td">unsigned hexadecimal, with lowercase      letters</td>    </tr>    <tr>      <td class="code-table-td">%X</td>      <td class="code-table-td">unsigned hexadecimal, with uppercase      letters</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">the argument shall be a pointer to an      integer into which is placed the number of characters written so      far</td>    </tr>    <tr>      <td class="code-table-td">%%</td>      <td class="code-table-td">a &#39;%&#39; sign</td>    </tr>  </table>  <p>An integer placed between a % sign and the format command acts as  a minimum field width specifier, and pads the output with spaces or  zeros to make it long enough. If you want to pad with zeros, place a  zero before the minimum field width specifier:</p>  <pre class="example-code">   %012d                </pre>  <p>You can also include a precision modifier, in the form of a .N  where N is some number, before the format command:</p>  <pre class="example-code">   %012.4d              </pre>  <p>The precision modifier has different meanings depending on the  format command being used:</p>  <ul>    <li>With %e, %E, and %f, the precision modifier lets you specify    the number of decimal places desired. For example, %12.6f will    display a floating number at least 12 digits wide, with six decimal    places.</li>    <li>With %g and %G, the precision modifier determines the maximum    number of significant digits displayed.</li>    <li>With %s, the precision modifer simply acts as a maximumfield    length, to complement the minimum field length that precedes the    period.</li>  </ul>  <p>All of printf()&#39;s output is right-justified, unless you place  a minus sign right after the % sign. For example,</p>  <pre class="example-code">   %-12.4f              </pre>  <p>will display a floating point number with a minimum of 12  characters, 4 decimal places, and left justified. You may modify the  %d, %i, %o, %u, and %x type specifiers with the letter l and the  letter h to specify long and short <a href="../data_types.html">data  types</a> (e.g. %hd means a short integer). The %e, %f, and %g type  specifiers can have the letter l before them to indicate that a  double follows. The %g, %f, and %e type specifiers can be preceded  with the character &#39;#&#39; to ensure that the decimal point will  be present, even if there are no decimal digits. The use of the  &#39;#&#39; character with the %x type specifier indicates that the  hexidecimal number should be printed with the &#39;0x&#39; prefix.  The use of the &#39;#&#39; character with the %o type specifier  indicates that the octal value should be displayed with a 0  prefix.</p>  <p>Inserting a plus sign '+' into the type specifier will force  positive values to be preceded by a '+' sign.  Putting a space  character ' ' there will force positive values to be preceded by a  single space character.</p>  <p>You can also include <a href="../escape_sequences.html">constant  escape sequences</a> in the output string.</p>  <p>The return value of printf() is the number of characters printed,  or a negative number if an error occurred.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fprintf.html">fprintf</a><br>    <a href="puts.html">puts</a><br>    <a href="scanf.html">scanf</a><br>    <a href="sprintf.html">sprintf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    putc  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int putc( int ch, FILE *stream );</pre>  <p>The putc() function writes the character <em>ch</em> to  <em>stream</em>. The return value is the character written, or  <strong>EOF</strong> if there is an error. For example:</p>  <pre class="example-code">   int ch;   FILE *input, *output;   input = fopen( &quot;tmp.c&quot;, &quot;r&quot; );   output = fopen( &quot;tmpCopy.c&quot;, &quot;w&quot; );   ch = getc( input );   while( ch != <strong>EOF</strong> ) {     putc( ch, output );     ch = getc( input );   }   fclose( input );   fclose( output );            </pre>  <p>generates a copy of the file tmp.c called tmpCopy.c.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="feof.html">feof</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="getc.html">getc</a><br>    <a href="getchar.html">getchar</a><br>    <a href="putchar.html">putchar</a><br>    <a href="puts.html">puts</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    putchar  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int putchar( int ch );</pre>  <p>The putchar() function writes <em>ch</em> to  <strong>stdout</strong>. The code</p>  <pre class="example-code">   putchar( ch );               </pre>  <p>is the same as</p>  <pre class="example-code">   putc( ch, <strong>stdout</strong> );         </pre>  <p>The return value of putchar() is the written character, or  <strong>EOF</strong> if there is an error.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="putc.html">putc</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    puts  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int puts( char *str );</pre>  <p>The function puts() writes <em>str</em> to  <strong>stdout</strong>. puts() returns non-negative on success, or  <strong>EOF</strong> on failure.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fputs.html">fputs</a><br>    <a href="gets.html">gets</a><br>    <a href="printf.html">printf</a><br>    <a href="putc.html">putc</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    remove  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int remove( const char *fname );</pre>  <p>The remove() function erases the file specified by <em>fname</em>.  The return value of remove() is zero upon success, and non-zero if  there is an error.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="rename.html">rename</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    rename  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;  int rename( const char *oldfname, const char *newfname );</pre>  <p>The function rename() changes the name of the file  <em>oldfname</em> to <em>newfname</em>. The return value of rename()  is zero upon success, non-zero on error.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="remove.html">remove</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    rewind  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;stdio.h&gt;

⌨️ 快捷键说明

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