📄 cppio_flags.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org"> <title>C++ I/O Flags</title> </head> <body bgcolor="#ffffff"> <table width="100%" bgcolor="#eeeeff"> <tr> <td><a href="index.html">cppreference.com</a> -> C++ I/O Flags</td> </tr> </table> <h1>C++ I/O Flags</h1> <p>C++ defines some format flags for standard input and output, which can be manipulated with the <a href="cppio_details.html#flags">flags()</a>, <a href="cppio_details.html#setf">setf()</a>, and <a href= "cppio_details.html#unsetf">unsetf()</a> functions. For example,</p><pre> cout.setf(ios::left);</pre> <p>turns on left justification for all output directed to <strong>cout</strong>.</p> <table align="center"> <tr> <th>Flag</th> <th>Meaning</th> </tr> <tr bgcolor="#eeeeff"> <td>boolalpha</td> <td>Boolean values can be input/output using the words "true" and "false".</td> </tr> <tr> <td>dec</td> <td>Numeric values are displayed in decimal.</td> </tr> <tr bgcolor="#eeeeff"> <td>fixed</td> <td>Display floating point values using normal notation (as opposed to scientific).</td> </tr> <tr> <td>hex</td> <td>Numeric values are displayed in hexidecimal.</td> </tr> <tr bgcolor="#eeeeff"> <td>internal</td> <td>If a numeric value is padded to fill a field, spaces are inserted between the sign and base character.</td> </tr> <tr> <td>left</td> <td>Output is left justified.</td> </tr> <tr bgcolor="#eeeeff"> <td>oct</td> <td>Numeric values are displayed in octal.</td> </tr> <tr> <td>right</td> <td>Output is right justified.</td> </tr> <tr bgcolor="#eeeeff"> <td>scientific</td> <td>Display floating point values using scientific notation.</td> </tr> <tr> <td>showbase</td> <td>Display the base of all numeric values.</td> </tr> <tr bgcolor="#eeeeff"> <td>showpoint</td> <td>Display a decimal and extra zeros, even when not needed.</td> </tr> <tr> <td>showpos</td> <td>Display a leading plus sign before positive numeric values.</td> </tr> <tr bgcolor="#eeeeff"> <td>skipws</td> <td>Discard whitespace characters (spaces, tabs, newlines) when reading from a stream.</td> </tr> <tr> <td>unitbuf</td> <td>Flush the buffer after each insertion.</td> </tr> <tr bgcolor="#eeeeff"> <td>uppercase</td> <td>Display the "e" of scientific notation and the "x" of hexidecimal notation as capital letters.</td> </tr> </table> <p>You can also manipulate flags indirectly, using the following <i>manipulators</i>. Most programmers are familiar with the <strong>endl</strong> manipulator, which might give you an idea of how manipulators are used. For example, to set the <i>dec</i> flag, you might use the following command:</p><pre> cout << dec;</pre> <table align="center"> <tr> <th colspan="4">Manipulators defined in <iostream></th> </tr> <tr> <th>Manipulator</th> <th>Description</th> <th>Input</th> <th>Output</th> </tr> <tr bgcolor="#eeeeff"> <td>boolalpha</td> <td>Turns on the boolalpha flag</td> <td>X</td> <td>X</td> </tr> <tr> <td>dec</td> <td>Turns on the dec flag</td> <td>X</td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>endl</td> <td>Output a newline character, flush the stream</td> <td> </td> <td>X</td> </tr> <tr> <td>ends</td> <td>Output a null character</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>fixed</td> <td>Turns on the fixed flag</td> <td> </td> <td>X</td> </tr> <tr> <td>flush</td> <td>Flushes the stream</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>hex</td> <td>Turns on the hex flag</td> <td>X</td> <td>X</td> </tr> <tr> <td>internal</td> <td>Turns on the internal flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>left</td> <td>Turns on the left flag</td> <td> </td> <td>X</td> </tr> <tr> <td>noboolalpha</td> <td>Turns off the boolalpha flag</td> <td>X</td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>noshowbase</td> <td>Turns off the showbase flag</td> <td> </td> <td>X</td> </tr> <tr> <td>noshowpoint</td> <td>Turns off the showpoint flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>noshowpos</td> <td>Turns off the showpos flag</td> <td> </td> <td>X</td> </tr> <tr> <td>noskipws</td> <td>Turns off the skipws flag</td> <td>X</td> <td> </td> </tr> <tr bgcolor="#eeeeff"> <td>nounitbuf</td> <td>Turns off the unitbuf flag</td> <td> </td> <td>X</td> </tr> <tr> <td>nouppercase</td> <td>Turns off the uppercase flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>oct</td> <td>Turns on the oct flag</td> <td>X</td> <td>X</td> </tr> <tr> <td>right</td> <td>Turns on the right flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>scientific</td> <td>Turns on the scientific flag</td> <td> </td> <td>X</td> </tr> <tr> <td>showbase</td> <td>Turns on the showbase flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>showpoint</td> <td>Turns on the showpoint flag</td> <td> </td> <td>X</td> </tr> <tr> <td>showpos</td> <td>Turns on the showpos flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>skipws</td> <td>Turns on the skipws flag</td> <td>X</td> <td> </td> </tr> <tr> <td>unitbuf</td> <td>Turns on the unitbuf flag</td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>uppercase</td> <td>Turns on the uppercase flag</td> <td> </td> <td>X</td> </tr> <tr> <td>ws</td> <td>Skip any leading whitespace</td> <td>X</td> <td> </td> </tr> </table> <table align="center"> <tr> <th colspan="4">Manipulators defined in <iomanip></th> </tr> <tr> <th>Manipulator</th> <th>Description</th> <th>Input</th> <th>Output</th> </tr> <tr bgcolor="#eeeeff"> <td>resetiosflags( long f )</td> <td>Turn off the flags specified by <i>f</i></td> <td>X</td> <td>X</td> </tr> <tr> <td>setbase( int base )</td> <td>Sets the number base to <i>base</i></td> <td> </td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>setfill( int ch )</td> <td>Sets the fill character to <i>ch</i></td> <td> </td> <td>X</td> </tr> <tr> <td>setiosflags( long f )</td> <td>Turn on the flags specified by <i>f</i></td> <td>X</td> <td>X</td> </tr> <tr bgcolor="#eeeeff"> <td>setprecision( int p )</td> <td>Sets the number of digits of precision</td> <td> </td> <td>X</td> </tr> <tr> <td>setw( int w )</td> <td>Sets the field width to <i>w</i></td> <td> </td> <td>X</td> </tr> </table> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -