the format control string

The format-control string contains format specifications that determine the output format for the arguments following the lpFmt parameter. Format specifications, discussed below, always begin with a percent sign (%). If a percent sign is followed by a character that has no meaning as a format field, the character is not formatted (for example, %% produces a single percent-sign character).

The format-control string is read from left to right. When the first format specification (if any) is encountered, it causes the value of the first argument after the format-control string to be converted and copied to the output buffer according to the format specification. The second format specification causes the second argument to be converted and copied, and so on. If there are more arguments than format specifications, the extra arguments are ignored. If there are not enough arguments for all of the format specifications, the results are undefined.

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).
0Pad the output value with zeros to fill the field width. If this field is omitted, the output value is padded with blank spaces.
widthCopy 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.
.precisionFor 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.
typeOutput the corresponding argument as a character, a string, or a number. This field can be any of the following values.
 ValueMeaning
 cSingle character. This value is interpreted as type WCHAR if the calling application defines Unicode and as type __wchar_t otherwise.
 CSingle character. This value is interpreted as type __wchar_t if the calling application defines Unicode and as type WCHAR otherwise.
 dSigned decimal integer. This value is equivalent to i.
 hc, hCSingle 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.
 hdSigned short integer argument.
 hs, hSString. This value is always interpreted as type LPSTR, even when the calling application defines Unicode.
 huUnsigned short integer.
 iSigned decimal integer. This value is equivalent to d.
 lc, lCSingle 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.
 ldLong signed integer. This value is equivalent to li.
 liLong signed integer. This value is equivalent to ld.
 ls, lSString. This value is always interpreted as type LPWSTR, even when the calling application does not define Unicode. This value is equivalent to ws.
 luLong unsigned integer.
 lx, lXLong unsigned hexadecimal integer in lowercase or uppercase.
 pWindows 2000/XP: Pointer. The address is printed using hexadecimal.
 sString. This value is interpreted as type LPWSTR when the calling application defines Unicode and as type LPSTR otherwise.
 SString. This value is interpreted as type LPSTR when the calling application defines Unicode and as type LPWSTR otherwise.
 uUnsigned integer argument.
 x, XUnsigned hexadecimal integer in lowercase or uppercase.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值