printf等函数中的格式控制
来源:互联网 发布:淘宝手机删除差评链接 编辑:程序博客网 时间:2024/04/28 06:55
This topic describes the syntax for format specifications fields, used in printf, wprintf and related functions. More secured versions of these functions are available, see printf_s, _printf_s_l, wprintf_s, _wprintf_s_l. For details on the individual functions, see the documentation for those specific functions. For a complete listing of these functions, see Stream I/O.
A format specification, which consists of optional and required fields, has the following form:
%[flags] [width] [.precision] [{h | l | ll | I | I32 | I64}]type
Each field of the format specification is a single character or a number signifying a particular format option. The simplest format specification contains only the percent sign and a type character (for example, %s). If a percent sign is followed by a character that has no meaning as a format field, the character is copied to stdout. For example, to print a percent-sign character, use %%.
The optional fields, which appear before the type character, control other aspects of the formatting, as follows:
Note If the argument corresponding to %s or %S is a null pointer, "(null)" will be displayed.
Note In all exponential formats, the default number of digits of exponent to display is three. Using the _set_output_format function, the number of digits displayed may be set to two, expanding to three if demanded by the size of exponent.
Security Note The %n format is inherently insecure and is disabled by default; if %n is encountered in a format string, the invalid parameter handler is invoked as described in Parameter Validation. To enable %n support, see _set_printf_count_output.
flags
The first optional field of the format specification is flags. A flag directive is a character that justifies output and prints signs, blanks, decimal points, and octal and hexadecimal prefixes. More than one flag directive may appear in a format specification.
Fl ag
Meaning
Default
–
Left align the result within the given field width.
Right align.
+
Prefix the output value with a sign (+ or –) if the output value is of a signed type.
Sign appears only for negative signed values (–).
0
If width is prefixed with 0, zeros are added until the minimum width is reached. If 0 and – appear, the 0 is ignored. If 0 is specified with an integer format (i, u, x, X, o, d) and a precision specification is also present (for example,%04.d), the 0 is ignored.
No padding.
blank(' ')
Prefix the output value with a blank if the output value is signed and positive; the blank is ignored if both the blank and + flags appear.
No blank appears.
#
When used with the o, x, or X format, the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively.
No blank appears.
When used with the e, E, f, a or A format, the # flag forces the output value to contain a decimal point in all cases.
Decimal point appears only if digits follow it.
When used with the g or G format, the # flag forces the output value to contain a decimal point in all cases and prevents the truncation of trailing zeros.
Ignored when used with c, d, i, u, or s.
Decimal point appears only if digits follow it. Trailing zeros are truncated.
- printf等函数中的格式控制
- printf()函数常用格式控制
- printf,wsprintf等格式控制符
- Printf()输出格式控制
- printf格式控制符
- Printf()输出格式控制
- Printf() 输出格式控制
- Printf()输出格式控制
- printf格式控制完整版
- Printf() 输出格式控制
- printf()输出格式控制
- PRINTF()输出格式控制
- Printf()输出格式控制
- Printf()输出格式控制
- Printf()输出格式控制
- Printf()输出格式控制
- printf格式控制
- printf格式控制符
- 设备管理与检修方式的发展史(转)
- 架构搭建系统(一)Struts2基础架构搭建全过程
- 多版本并发控制(MVCC)在分布式系统中的应用
- 有关likely和unlikely
- gdb简介
- printf等函数中的格式控制
- linux内存映射函数mmap
- php程序实现多线程处理
- MAXIMO 开发方法_一个字段类的开发
- Oracle数据库的varchar2(2)存储一个汉字时提示插入汉字过长问题
- 深入浅出学习GIT(一)
- 使用委托
- 升级日志_20120105(重大突破!!!)
- Wp7,使你的程序在程序列表中的名称自适应手机语言设置