?
This document uses PHP Chinese website manual Release
在頭文件<wchar.h>中定義 | ||
---|---|---|
int wprintf(const wchar_t * format,...); | (自C95以來)(直到C99) | |
int wprintf(const wchar_t * restrict format,...); | (自C99以來) | |
int fwprintf(FILE * stream,const wchar_t * format,...); | (自C95以來)(直到C99) | |
int fwprintf(FILE * restrict stream,const wchar_t * restrict format,...); | (自C99以來) | |
int swprintf(wchar_t * buffer,size_t bufsz,const wchar_t * format,...); | (自C95以來)(直到C99) | |
int swprintf(wchar_t * restrict buffer,size_t bufsz,const wchar_t * restrict format,...); | (自C99以來) | |
int wprintf_s(const wchar_t * restrict format,...); | (自C11以來) | |
int fwprintf_s(FILE * restrict stream,const wchar_t * restrict format,...); | (自C11以來) | |
int swprintf_s(wchar_t * restrict buffer,rsize_t bufsz,const wchar_t * restrict format,...); | (自C11以來) | |
int snwprintf_s(wchar_t * restrict s,rsize_t n,const wchar_t * restrict format,...); | (自C11以來) |
從給定的位置加載數(shù)據(jù),將它們轉(zhuǎn)換為寬字符串等值并將結(jié)果寫入各種接收器。
1)將結(jié)果寫入stdout
。
2)將結(jié)果寫入文件流stream
。
3)如果bufsz
大于零,則將結(jié)果寫入寬字符串buffer
。最bufsz-1
寬字符后面跟著空寬字符。如果bufsz
為零,則不會(huì)寫入任何內(nèi)容(并且buffer
可能是空指針),但返回值(將寫入的寬字符數(shù))仍然會(huì)計(jì)算并返回。
4-6)與(1-3)相同,但在運(yùn)行時(shí)檢測(cè)到以下錯(cuò)誤并調(diào)用當(dāng)前安裝的約束處理函數(shù):
轉(zhuǎn)換說明符%n
存在于format
任何對(duì)應(yīng)的參數(shù)%s
都是空指針
format
或者buffer
是空指針
bufsz
是零或大于 RSIZE_MAX/sizeof(wchar_t)
編碼錯(cuò)誤出現(xiàn)在任何字符串和字符轉(zhuǎn)換說明符中
(僅限于swprintf_s
)要寫入的寬字符數(shù)(包括null)將超過bufsz
。
7)與(6)相同,只是它會(huì)截?cái)嘟Y(jié)果以適應(yīng)s所指向的數(shù)組。由于所有的邊界檢查功能,wprintf_s
,wfprintf_s
,和wsprintf_s
僅保證可供如果__STDC_LIB_EXT1__
由實(shí)現(xiàn)所定義,并且如果用戶定義__STDC_WANT_LIB_EXT1__
的整數(shù)常數(shù)1
,包括之前<stdio.h>
。
流 | - | 輸出文件流寫入 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
緩沖 | - | 指向要寫入的寬字符字符串的指針 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bufsz | - | 最多可以寫入bufsz-1寬字符,加上空終止符 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
格式 | - | pointer to a null-terminated wide string specifying how to interpret the data. The format string consists of ordinary wide characters (except %), which are copied unchanged into the output stream, and conversion specifications. Each conversion specification has the following format: introductory % character (optional) one or more flags that modify the behavior of the conversion: -: the result of the conversion is left-justified within the field (by default it is right-justified) +: the sign of signed conversions is always prepended to the result of the conversion (by default the result is preceded by minus only when it is negative) space: if the result of a signed conversion does not start with a sign character, or is empty, space is prepended to the result. It is ignored if + flag is present. # : alternative form of the conversion is performed. See the table below for exact effects otherwise the behavior is undefined. 0 : for integer and floating point number conversions, leading zeros are used to pad the field instead of space characters. For integer numbers it is ignored if the precision is explicitly specified. For other conversions using this flag results in undefined behavior. It is ignored if - flag is present. (optional) integer value or * that specifies minimum field width. The result is padded with space characters (by default), if required, on the left when right-justified, or on the right if left-justified. In the case when * is used, the width is specified by an additional argument of type int. If the value of the argument is negative, it results with the - flag specified and positive field width. (Note: This is the minimum width: The value is never truncated.) (optional) . followed by integer number or *, or neither that specifies precision of the conversion. In the case when * is used, the precision is specified by an additional argument of type int. If the value of this argument is negative, it is ignored. If neither a number nor * is used, the precision is taken as zero. See the table below for exact effects of precision. (optional) length modifier that specifies the size of the argument conversion format specifier The following format specifiers are available: Conversion specifier Explanation Argument type length modifier hh (C99). h (none) l ll (C99). j (C99). z (C99). t (C99). L % writes literal %. The full conversion specification must be %%. N/A N/A N/A N/A N/A N/A N/A N/A N/A c writes a single character. The argument is first converted to wchar_t as if by calling btowc. If the l modifier is used, the wint_t argument is first converted to wchar_t. N/A N/A int wint_t N/A N/A N/A N/A N/A s writes a character string The argument must be a pointer to the initial element of a character array containing a multibyte character sequence beginning in the initial shift state, which is converted to wide character array as if by a call to mbrtowc with zero-initialized conversion state. Precision specifies the maximum number of wide characters to be written. If Precision is not specified, writes every wide characters up to and not including the first null terminator. If the l specifier is used, the argument must be a pointer to the initial element of an array of wchar_t. N/A N/A char* wchar_t* N/A N/A N/A N/A N/A d i converts a signed integer into decimal representation -dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. signed char short int long long long intmax_t signed size_t ptrdiff_t N/A o converts a unsigned integer into octal representation oooo. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation precision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are 0, single 0 is written. unsigned char unsigned short unsigned int unsigned long unsigned long long uintmax_t size_t unsigned version of ptrdiff_t N/A x X converts an unsigned integer into hexadecimal representation hhhh. For the x conversion letters abcdef are used. For the X conversion letters ABCDEF are used. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation 0x or 0X is prefixed to results if the converted value is nonzero. N/A u converts an unsigned integer into decimal representation dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. N/A f F converts floating-point number to the decimal notation in the style -ddd.ddd. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. N/A N/A double double (C99) N/A N/A N/A N/A long double e E converts floating-point number to the decimal exponent notation. For the e conversion style -d.ddde±dd is used. For the E conversion style -d.dddE±dd is used. The exponent contains at least two digits, more digits are used only if necessary. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. N/A N/A N/A N/A N/A N/A a A (C99). converts floating-point number to the hexadecimal exponent notation. For the a conversion style -0xh.hhhp±d is used. For the A conversion style -0Xh.hhhP±d is used. The first hexadecimal digit is 0 if the argument is not a normalized floating point value. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is sufficient for exact representation of the value. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. N/A N/A N/A N/A N/A N/A g G converts floating-point number to decimal or decimal exponent notation depending on the value and the precision. For the g conversion style conversion with style e or f will be performed. For the G conversion style conversion with style E or F will be performed. Let P equal the precision if nonzero, 6 if the precision is not specified, or 1 if the precision is 0. Then, if a conversion with style E would have an exponent of X: if P > X ≥ ?4, the conversion is with style f or F and precision P ? 1 ? X. otherwise, the conversion is with style e or E and precision P ? 1. Unless alternative representation is requested the trailing zeros are removed, also the decimal point character is removed if no fractional part is left. For infinity and not-a-number conversion style see notes. N/A N/A N/A N/A N/A N/A n returns the number of characters written so far by this call to the function. The result is written to the value pointed to by the argument. The specification may not contain any flag, field width, or precision. signed char* short* int* long* long long* intmax_t* signed size_t* ptrdiff_t* N/A p writes an implementation defined character sequence defining a pointer. N/A N/A void* N/A N/A N/A N/A N/A N/A The floating point conversion functions convert infinity to inf or infinity. Which one is used is implementation defined. Not-a-number is converted to nan or nan(char_sequence). Which one is used is implementation defined. The conversions F, E, G, A output INF, INFINITY, NAN instead. Even though %c expects int argument, it is safe to pass a char because of the integer promotion that takes place when a variadic function is called. The correct conversion specifications for the fixed-width character types (int8_t, etc) are defined in the header <inttypes.h> (although PRIdMAX, PRIuMAX, etc is synonymous with %jd, %ju, etc). The memory-writing conversion specifier %n is a common target of security exploits where format strings depend on user input and is not supported by the bounds-checked printf_s family of functions. There is a sequence point after the action of each conversion specifier; this permits storing multiple %n results in the same variable or, as an edge case, printing a string modified by an earlier %n within the same call. If a conversion specification is invalid, the behavior is undefined. | Conversion specifier | Explanation | Argument type | length modifier | hh (C99). | h | (none) | l | ll (C99). | j (C99). | z (C99). | t (C99). | L | % | writes literal %. The full conversion specification must be %%. | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | c | writes a single character. The argument is first converted to wchar_t as if by calling btowc. If the l modifier is used, the wint_t argument is first converted to wchar_t. | N/A | N/A | int | wint_t | N/A | N/A | N/A | N/A | N/A | s | writes a character string The argument must be a pointer to the initial element of a character array containing a multibyte character sequence beginning in the initial shift state, which is converted to wide character array as if by a call to mbrtowc with zero-initialized conversion state. Precision specifies the maximum number of wide characters to be written. If Precision is not specified, writes every wide characters up to and not including the first null terminator. If the l specifier is used, the argument must be a pointer to the initial element of an array of wchar_t. | N/A | N/A | char* | wchar_t* | N/A | N/A | N/A | N/A | N/A | d i | converts a signed integer into decimal representation -dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | signed char | short | int | long | long long | intmax_t | signed size_t | ptrdiff_t | N/A | o | converts a unsigned integer into octal representation oooo. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation precision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are 0, single 0 is written. | unsigned char | unsigned short | unsigned int | unsigned long | unsigned long long | uintmax_t | size_t | unsigned version of ptrdiff_t | N/A | x X | converts an unsigned integer into hexadecimal representation hhhh. For the x conversion letters abcdef are used. For the X conversion letters ABCDEF are used. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation 0x or 0X is prefixed to results if the converted value is nonzero. | N/A | u | converts an unsigned integer into decimal representation dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | N/A | f F | converts floating-point number to the decimal notation in the style -ddd.ddd. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | double | double (C99) | N/A | N/A | N/A | N/A | long double | e E | converts floating-point number to the decimal exponent notation. For the e conversion style -d.ddde±dd is used. For the E conversion style -d.dddE±dd is used. The exponent contains at least two digits, more digits are used only if necessary. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | a A (C99). | converts floating-point number to the hexadecimal exponent notation. For the a conversion style -0xh.hhhp±d is used. For the A conversion style -0Xh.hhhP±d is used. The first hexadecimal digit is 0 if the argument is not a normalized floating point value. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is sufficient for exact representation of the value. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | g G | converts floating-point number to decimal or decimal exponent notation depending on the value and the precision. For the g conversion style conversion with style e or f will be performed. For the G conversion style conversion with style E or F will be performed. Let P equal the precision if nonzero, 6 if the precision is not specified, or 1 if the precision is 0. Then, if a conversion with style E would have an exponent of X: if P > X ≥ ?4, the conversion is with style f or F and precision P ? 1 ? X. otherwise, the conversion is with style e or E and precision P ? 1. Unless alternative representation is requested the trailing zeros are removed, also the decimal point character is removed if no fractional part is left. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | n | returns the number of characters written so far by this call to the function. The result is written to the value pointed to by the argument. The specification may not contain any flag, field width, or precision. | signed char* | short* | int* | long* | long long* | intmax_t* | signed size_t* | ptrdiff_t* | N/A | p | writes an implementation defined character sequence defining a pointer. | N/A | N/A | void* | N/A | N/A | N/A | N/A | N/A | N/A |
Conversion specifier | Explanation | Argument type | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
length modifier | hh (C99). | h | (none) | l | ll (C99). | j (C99). | z (C99). | t (C99). | L | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
% | writes literal %. The full conversion specification must be %%. | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
c | writes a single character. The argument is first converted to wchar_t as if by calling btowc. If the l modifier is used, the wint_t argument is first converted to wchar_t. | N/A | N/A | int | wint_t | N/A | N/A | N/A | N/A | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
s | writes a character string The argument must be a pointer to the initial element of a character array containing a multibyte character sequence beginning in the initial shift state, which is converted to wide character array as if by a call to mbrtowc with zero-initialized conversion state. Precision specifies the maximum number of wide characters to be written. If Precision is not specified, writes every wide characters up to and not including the first null terminator. If the l specifier is used, the argument must be a pointer to the initial element of an array of wchar_t. | N/A | N/A | char* | wchar_t* | N/A | N/A | N/A | N/A | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
d i | converts a signed integer into decimal representation -dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | signed char | short | int | long | long long | intmax_t | signed size_t | ptrdiff_t | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
o | converts a unsigned integer into octal representation oooo. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation precision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are 0, single 0 is written. | unsigned char | unsigned short | unsigned int | unsigned long | unsigned long long | uintmax_t | size_t | unsigned version of ptrdiff_t | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x X | converts an unsigned integer into hexadecimal representation hhhh. For the x conversion letters abcdef are used. For the X conversion letters ABCDEF are used. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation 0x or 0X is prefixed to results if the converted value is nonzero. | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
u | converts an unsigned integer into decimal representation dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f F | converts floating-point number to the decimal notation in the style -ddd.ddd. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | double | double (C99) | N/A | N/A | N/A | N/A | long double | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
e E | converts floating-point number to the decimal exponent notation. For the e conversion style -d.ddde±dd is used. For the E conversion style -d.dddE±dd is used. The exponent contains at least two digits, more digits are used only if necessary. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
a A (C99). | 將浮點(diǎn)數(shù)轉(zhuǎn)換為十六進(jìn)制指數(shù)表示法。對(duì)于轉(zhuǎn)換類型,使用-0xh.hhhp±d。對(duì)于A轉(zhuǎn)換樣式,使用-0Xh.hhhP±d。如果參數(shù)不是標(biāo)準(zhǔn)化的浮點(diǎn)值,則第一個(gè)十六進(jìn)制數(shù)字為0。如果該值為0,則指數(shù)也為0。精度指定小數(shù)點(diǎn)后面出現(xiàn)的最小位數(shù)。默認(rèn)精度足以精確表示值。在替代實(shí)現(xiàn)中,即使沒有數(shù)字跟隨它,也會(huì)寫入小數(shù)點(diǎn)字符。對(duì)于無窮大和非數(shù)字轉(zhuǎn)換風(fēng)格,請(qǐng)參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
g G | 根據(jù)值和精度將浮點(diǎn)數(shù)轉(zhuǎn)換為十進(jìn)制或十進(jìn)制指數(shù)符號(hào)。對(duì)于使用樣式e或f的g轉(zhuǎn)換樣式轉(zhuǎn)換將被執(zhí)行。對(duì)于G轉(zhuǎn)換樣式,將使用樣式E或F進(jìn)行轉(zhuǎn)換。假設(shè)P等于非零的精度,如果未指定精度,則等于6;如果精度為0,則等于1。然后,如果具有樣式E的轉(zhuǎn)換將具有X的指數(shù):如果P> X≥-4,則轉(zhuǎn)換具有樣式f或F和精度P-1-X。否則,轉(zhuǎn)換具有樣式e或E以及精度P - 1.除非要求替代表示,否則尾隨零將被刪除,如果沒有剩余小數(shù)部分,小數(shù)點(diǎn)字符也會(huì)被刪除。對(duì)于無窮大和非數(shù)字轉(zhuǎn)換風(fēng)格,請(qǐng)參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? | 將此調(diào)用到目前為止寫入的字符數(shù)返回給該函數(shù)。結(jié)果寫入?yún)?shù)指向的值。規(guī)范可能不包含任何標(biāo)志,字段寬度或精度。 | 簽名字符* | 短* | INT * | long* | 很長(zhǎng)* | *將intmax_t | 簽名size_t * | ptrdiff_t的* | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p | 寫一個(gè)實(shí)現(xiàn)定義的字符序列來定義一個(gè)指針。 | N / A | N / A | 無效* | N / A | N / A | N / A | N / A | N / A | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
... | - | 指定要打印的數(shù)據(jù)的參數(shù) |
介紹%
人物
(可選)一個(gè)或多個(gè)修改轉(zhuǎn)換行為的標(biāo)志:
-
:轉(zhuǎn)換的結(jié)果在字段內(nèi)左對(duì)齊(默認(rèn)情況下它是右對(duì)齊的)
+
:帶符號(hào)轉(zhuǎn)換的符號(hào)總是預(yù)設(shè)為轉(zhuǎn)換結(jié)果的前綴(默認(rèn)情況下結(jié)果前面為減號(hào),僅當(dāng)它為負(fù)值時(shí))
空格:如果簽名轉(zhuǎn)換的結(jié)果不是以符號(hào)字符開頭,或者是空的,則空格會(huì)預(yù)設(shè)為結(jié)果。如果+
存在標(biāo)志,則忽略它。
#
:執(zhí)行轉(zhuǎn)換的替代形式。請(qǐng)參閱下表以了解確切的效果,否則行為未定義。
0
:對(duì)于整數(shù)和浮點(diǎn)數(shù)轉(zhuǎn)換,前導(dǎo)零用于填充字段而不是空格字符。對(duì)于整數(shù),如果明確指定了精度,它將被忽略。對(duì)于使用此標(biāo)志的其他轉(zhuǎn)換會(huì)導(dǎo)致未定義的行為。如果-
存在標(biāo)志,則忽略它。
(可選)整數(shù)值或*
指定最小字段寬度。如果需要,結(jié)果會(huì)填充空格字符(默認(rèn)情況下),右側(cè)對(duì)齊時(shí)填充空白字符,左側(cè)填充右側(cè)填充。在使用的情況下*
,寬度由類型的附加參數(shù)指定int
。如果參數(shù)的值是負(fù)數(shù),則結(jié)果是-
指定的標(biāo)志和正的字段寬度。(注意:這是最小寬度:該值從不被截?cái)?。?/p>
(可選).
后面跟隨整數(shù)或者*
或者既不指定轉(zhuǎn)換的精度。在使用的情況下*
,精度由類型的附加參數(shù)指定int
。如果這個(gè)參數(shù)的值是負(fù)數(shù),它將被忽略。如果既不使用數(shù)字也不*
使用,則精度取為零。請(qǐng)參閱下表以了解精確度的確切影響。
(可選)長(zhǎng)度修飾符,用于指定參數(shù)的大小
轉(zhuǎn)換格式說明符
以下格式說明符可用:
Conversion
說明符說明參數(shù)類型長(zhǎng)度修飾符 hh
(C99)。
h
(none) l
ll
(C99).
j
(C99).
z
(C99).
t
(C99).
L
%
寫文字%
。完整的轉(zhuǎn)換規(guī)范必須是%%
。N / AN / AN / AN / AN / AN / AN / AN / AN / A c
寫入單個(gè)字符。參數(shù)首先被轉(zhuǎn)換wchar_t
為仿佛通過調(diào)用btowc
。如果使用l修飾符,wint_t
則首先將參數(shù)轉(zhuǎn)換為wchar_t
。
N/A N/A int
wint_t
N / AN / AN / AN / AN / A s
寫入字符串參數(shù)必須是一個(gè)指向字符數(shù)組初始元素的指針,該字符數(shù)組包含一個(gè)多字節(jié)字符序列,從初始移位狀態(tài)開始,轉(zhuǎn)換為寬字符數(shù)組,如同通過調(diào)用mbrtowc
具有零初始化轉(zhuǎn)換狀態(tài)。Precision指定要寫入的最大寬字符數(shù)。如果未指定Precision,則將每個(gè)寬字符寫入并不包括第一個(gè)空終止符。如果使用l說明符,參數(shù)必須是指向數(shù)組的初始元素的指針wchar_t
。
N/A N/A char*
wchar_t*
N/A N/A N/A N/A N/A d
i
將有符號(hào)的整數(shù)轉(zhuǎn)換為十進(jìn)制表示形式-dddd。 精度指定出現(xiàn)的最小位數(shù)。默認(rèn)的精度是1
。
如果轉(zhuǎn)換后的值和精度都是0
沒有字符的轉(zhuǎn)換結(jié)果。
signed char
short
int
long
long long
intmax_t
signed size_t
ptrdiff_t
N / A o
將無符號(hào)整數(shù)轉(zhuǎn)換為八進(jìn)制表示oooo。 精度指定出現(xiàn)的最小位數(shù)。默認(rèn)的精度是1
。如果轉(zhuǎn)換后的值和精度都是0
沒有字符的轉(zhuǎn)換結(jié)果。在替代實(shí)現(xiàn)中,如果需要,可以增加精度以寫入一個(gè)前導(dǎo)零。在這種情況下,如果轉(zhuǎn)換值和精度都是0
,0
寫入單個(gè)。
unsigned char
unsigned short
unsigned int
unsigned long
unsigned long long
uintmax_t
size_t
未簽名的版本 ptrdiff_t
N/A x
X
將無符號(hào)整數(shù)轉(zhuǎn)換為十六進(jìn)制表示hhhh。使用x
轉(zhuǎn)換字母abcdef
。
使用X
轉(zhuǎn)換字母ABCDEF
。
精度指定出現(xiàn)的最小位數(shù)。默認(rèn)的精度是1
。如果轉(zhuǎn)換后的值和精度都是0
沒有字符的轉(zhuǎn)換結(jié)果。在替代實(shí)現(xiàn)中, 0x
或者0X
如果轉(zhuǎn)換后的值不為零,則將其作為結(jié)果的前綴。
N / A u
將無符號(hào)整數(shù)轉(zhuǎn)換為十進(jìn)制表示形式dddd。 精度指定出現(xiàn)的最小位數(shù)。默認(rèn)的精度是1
。如果轉(zhuǎn)換后的值和精度都是0
沒有字符的轉(zhuǎn)換結(jié)果。
N/A f
F
將浮點(diǎn)數(shù)轉(zhuǎn)換為樣式-ddd.ddd中的小數(shù)表示法。 精度指定小數(shù)點(diǎn)后面出現(xiàn)的最小位數(shù)。默認(rèn)的精度是6
。在替代實(shí)現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點(diǎn)字符也會(huì)被寫入。對(duì)于無窮大和非數(shù)字轉(zhuǎn)換風(fēng)格,請(qǐng)參閱注釋。
N/A N/A double
`double` (C99)
N/A N/A N/A N/A long double
`e`
E
將浮點(diǎn)數(shù)轉(zhuǎn)換為十進(jìn)制指數(shù)符號(hào)。對(duì)于e
轉(zhuǎn)換樣式,使用-d.ddd e
±dd。
對(duì)于E
轉(zhuǎn)換樣式,使用-d.ddd E
±dd。
指數(shù)至少包含兩位數(shù)字,只有在必要時(shí)才使用更多數(shù)字。如果值是0
,指數(shù)也是0
。精度指定小數(shù)點(diǎn)后面出現(xiàn)的最小位數(shù)。默認(rèn)的精度是6
。在替代實(shí)現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點(diǎn)字符也會(huì)被寫入。對(duì)于無窮大和非數(shù)字轉(zhuǎn)換風(fēng)格,請(qǐng)參閱注釋。
N/A N/A N/A N/A N/A N/A a
A
(C99).
將浮點(diǎn)數(shù)轉(zhuǎn)換為十六進(jìn)制指數(shù)表示法。對(duì)于a
轉(zhuǎn)換樣式- 使用0x
h.hhh p
±d。
對(duì)于A
轉(zhuǎn)換樣式- 使用0X
h.hhh P
±d。
0
如果參數(shù)不是標(biāo)準(zhǔn)化的浮點(diǎn)值,則第一個(gè)十六進(jìn)制數(shù)字是。如果值是0
,指數(shù)也是0
。精度指定小數(shù)點(diǎn)后面出現(xiàn)的最小位數(shù)。默認(rèn)精度足以精確表示值。在替代實(shí)現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點(diǎn)字符也會(huì)被寫入。對(duì)于無窮大和非數(shù)字轉(zhuǎn)換風(fēng)格,請(qǐng)參閱注釋。
N/A N/A N/A N/A N/A N/A g
G
根據(jù)值和精度 將浮點(diǎn)數(shù)轉(zhuǎn)換為十進(jìn)制或十進(jìn)制指數(shù)符號(hào)。對(duì)于風(fēng)格轉(zhuǎn)換的轉(zhuǎn)換與風(fēng)格或?qū)⒈粓?zhí)行。gef
對(duì)于G
風(fēng)格轉(zhuǎn)換的轉(zhuǎn)換與風(fēng)格E
或F
將被執(zhí)行。
讓P
等于精度如果非零,6
如果沒有指定精度,或者1
如果精度是0
。然后,如果具有樣式的轉(zhuǎn)換E
將具有以下指數(shù)X
:
如果P> X≥-4,轉(zhuǎn)換是用式f
或F
和精度P - 1 - X。
否則,轉(zhuǎn)換采用樣式e
或E
精度P - 1。
除非請(qǐng)求替代表示,否則尾隨零將被刪除,如果沒有剩余小數(shù)部分,小數(shù)點(diǎn)字符也會(huì)被刪除。對(duì)于無窮大和非數(shù)字轉(zhuǎn)換風(fēng)格,請(qǐng)參閱注釋。
不適用/不適用/不適用/不適用/ n
返回此函數(shù)迄今為止寫入的字符數(shù)。結(jié)果寫入參數(shù)指向的值。規(guī)范可能不包含任何標(biāo)志,字段寬度或精度。
signed char*
short*
int*
long*
long long*
intmax_t*
signed size_t*
ptrdiff_t*
N / A p
寫入一個(gè)實(shí)現(xiàn)定義的字符序列來定義一個(gè)指針。不適用不適用不適用不適用不適用不適用 void*
浮點(diǎn)轉(zhuǎn)換函數(shù)將無窮大轉(zhuǎn)換為inf
或infinity
。使用哪一個(gè)是實(shí)現(xiàn)定義的。
非數(shù)字轉(zhuǎn)換為nan
或。使用哪一個(gè)是實(shí)現(xiàn)定義的。nan(char_sequence)
該轉(zhuǎn)換F
,E
,G
,A
輸出INF
,INFINITY
,NAN
來代替。
即使%c
需要int
參數(shù),通過char
調(diào)用可變參數(shù)函數(shù)時(shí)發(fā)生的整數(shù)提升也是安全的。
對(duì)于固定寬度的字符類型(正確的轉(zhuǎn)換規(guī)格int8_t
<inttypes.h>還(雖然,等等)都在頭定義PRIdMAX
,PRIuMAX
等是同義詞%jd
,%ju
等)。
內(nèi)存寫入轉(zhuǎn)換說明符%n
是安全漏洞的常見目標(biāo),其中格式字符串取決于用戶輸入,并且不受邊界檢查printf_s
函數(shù)族的支持。
每個(gè)轉(zhuǎn)換說明符的操作之后都有一個(gè)序列點(diǎn); 這允許將多個(gè)%n
結(jié)果存儲(chǔ)在相同的變量中,或者作為邊緣情況,%n
在同一個(gè)調(diào)用中打印由較早修改的字符串。
如果轉(zhuǎn)換規(guī)范無效,則行為未定義。
... - arguments specifying data to print
1,2)如果發(fā)生錯(cuò)誤,則成功寫入寬字符數(shù)或?qū)懭胴?fù)值。
3)如果編碼錯(cuò)誤發(fā)生或者如果要生成的字符數(shù)等于或大于size
(包括當(dāng)size
為零時(shí)),則寫入的寬字符的數(shù)目(不包括終止空寬字符)如果成功或負(fù)值。
4,5)如果發(fā)生錯(cuò)誤,則成功寫入寬字符數(shù)或?qū)懭胴?fù)值。
6)寫入的寬字符數(shù)(不包括終止空值)buffer
。返回編碼錯(cuò)誤和溢出時(shí)的負(fù)值。對(duì)所有其他錯(cuò)誤返回零。
7)的,將已經(jīng)寫入寬字符(不包括終止空)數(shù)量buffer
已經(jīng)bufsz
如果發(fā)生錯(cuò)誤,已經(jīng)足夠大時(shí),或?yàn)樨?fù)值。(也就是說,只有當(dāng)回報(bào)是非負(fù)的且小于時(shí),寫才能成功并且完成bufsz
)
雖然窄字符串提供snprintf
了可以確定所需的輸出緩沖區(qū)大小的可能性,但對(duì)于寬字符串沒有等效(直到C11的snwprintf_s),并且為了確定緩沖區(qū)大小,程序可能需要調(diào)用swprintf
,檢查結(jié)果值,并重新分配一個(gè)更大的緩沖區(qū),再次嘗試直到成功。
snwprintf_s
不同swprintf_s
,將截?cái)嘟Y(jié)果以適應(yīng)指向的數(shù)組buffer
,即使截?cái)啾淮蠖鄶?shù)邊界檢查函數(shù)視為錯(cuò)誤。
#include <locale.h>#include <wchar.h> int main(void){ char narrow_str[] = "z\u00df\u6c34\U0001f34c"; // or "z?水?" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9f\x8d\x8c"; wchar_t warr[29]; // the expected string is 28 characters plus 1 null terminator setlocale(LC_ALL, "en_US.utf8"); swprintf(warr, sizeof warr/sizeof *warr, L"Converted from UTF-8: '%s'", narrow_str); wprintf(L"%ls\n", warr);}
輸出:
Converted from UTF-8: 'z?水?'
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.29.2.1 fwprintf函數(shù)(p:403-410)
7.29.2.3 swprintf函數(shù)(p:416)
7.29.2.11 wprintf函數(shù)(p:421)
K.3.9.1.1 fwprintf_s函數(shù)(p:628)
K.3.9.1.4 swprintf_s函數(shù)(p:630-631)
K.3.9.1.13 wprintf_s函數(shù)(p:637-638)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.24.2.1 fwprintf函數(shù)(p:349-356)
7.24.2.3 swprintf函數(shù)(p:362)
7.24.2.11 wprintf函數(shù)(p:366)