printf,wsprintf等格式控制符

来源:互联网 发布:java控件 编辑:程序博客网 时间:2024/06/10 01:11


http://msdn.microsoft.com/en-us/library/windows/desktop/ms647550(v=vs.85).aspx

A format specification has the following form:

%[-][#][0][width][.precision]type

Each field is a single character or a number signifying a particular format option. The type characters that appear after the last optional format field determine whether the associated argument is interpreted as a character, a string, or a number. The simplest format specification contains only the percent sign and a type character (for example, %s). The optional fields control other aspects of the formatting. Following are the optional and required fields and their meanings.

FieldMeaning-

Pad the output with blanks or zeros to the right to fill the field width, justifying output to the left. If this field is omitted, the output is padded to the left, justifying it to the right.

#

Prefix hexadecimal values with 0x (lowercase) or 0X (uppercase).

0

Pad the output value with zeros to fill the field width. If this field is omitted, the output value is padded with blank spaces.

width

Copy the specified minimum number of characters to the output buffer. The width field is a nonnegative integer. The width specification never causes a value to be truncated; if the number of characters in the output value is greater than the specified width, or if the width field is not present, all characters of the value are printed, subject to the precision specification.

.precision

For numbers, copy the specified minimum number of digits to the output buffer. If the number of digits in the argument is less than the specified precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds the specified precision. If the specified precision is 0 or omitted entirely, or if the period (.) appears without a number following it, the precision is set to 1.

For strings, copy the specified maximum number of characters to the output buffer.

type

Output the corresponding argument as a character, a string, or a number. This field can be any of the following values.

c

Single character. This value is interpreted as type WCHAR if the calling application defines Unicode and as type __wchar_totherwise.

C

Single character. This value is interpreted as type __wchar_t if the calling application defines Unicode and as type WCHARotherwise.

d

Signed decimal integer. This value is equivalent to i.

hc, hC

Single character. The wsprintf function ignores character arguments with a numeric value of zero. This value is always interpreted as type __wchar_t, even when the calling application defines Unicode.

hd

Signed short integer argument.

hs, hS

String. This value is always interpreted as type LPSTR, even when the calling application defines Unicode.

hu

Unsigned short integer.

i

Signed decimal integer. This value is equivalent to d.

lc, lC

Single character. The wsprintf function ignores character arguments with a numeric value of zero. This value is always interpreted as type WCHAR, even when the calling application does not define Unicode.

ld

Long signed integer. This value is equivalent to li.

li

Long signed integer. This value is equivalent to ld.

ls, lS

String. This value is always interpreted as type LPWSTR, even when the calling application does not define Unicode. This value is equivalent to ws.

lu

Long unsigned integer.

lx, lX

Long unsigned hexadecimal integer in lowercase or uppercase.

p

Pointer. The address is printed using hexadecimal.

s

String. This value is interpreted as type LPWSTR when the calling application defines Unicode and as type LPSTRotherwise.

S

String. This value is interpreted as type LPSTR when the calling application defines Unicode and as type LPWSTRotherwise.

u

Unsigned integer argument.

x, X

Unsigned hexadecimal integer in lowercase or uppercase.