?
This document uses PHP Chinese website manual Release
Defined in header <wchar.h> | ||
---|---|---|
(1) | ||
int vwprintf( const wchar_t *format, va_list vlist ); | (since C95) (until C99) | |
int vwprintf( const wchar_t *restrict format, va_list vlist ); | (since C99) | |
(2) | ||
int vfwprintf( FILE* stream, const wchar_t *format, va_list vlist ); | (since C95) (until C99) | |
int vfwprintf( FILE *restrict stream, const wchar_t *restrict format, va_list vlist ); | (since C99) | |
(3) | ||
int vswprintf( wchar_t *buffer, size_t bufsz, const wchar_t *format, va_list vlist ); | (since C95) (until C99) | |
int vswprintf( wchar_t *restrict buffer, size_t bufsz, const wchar_t *restrict format, va_list vlist ); | (since C99) | |
int vwprintf_s( const wchar_t *restrict format, va_list vlist); | (4) | (since C11) |
int vfwprintf_s( FILE * restrict stream, const wchar_t *restrict format, va_list vlist); | (5) | (since C11) |
int vswprintf_s( wchar_t *restrict buffer, rsize_t bufsz, const wchar_t * restrict format, va_list vlist); | (6) | (since C11) |
int vsnwprintf_s( wchar_t *restrict buffer, rsize_t bufsz, const wchar_t *restrict format, va_list vlist); | (7) | (since C11) |
加載來自定義位置的數(shù)據(jù)vlist
,將它們轉(zhuǎn)換為寬字符串,并將結(jié)果寫入各種接收器。
1)將結(jié)果寫入stdout
。
2)將結(jié)果寫入文件流stream
。
3)將結(jié)果寫入一個寬字符串buffer
。最bufsz-1
寬字符后面跟著空寬字符。生成的寬字符串將以空寬字符結(jié)尾,除非bufsz
為零。
4-7)與(1-3)相同,只是在運行時檢測到以下錯誤并調(diào)用當前安裝的約束處理函數(shù):
轉(zhuǎn)換說明符%n
存在于format
任何對應的參數(shù)%s
都是空指針
format
或者buffer
是空指針
bufsz
是零或大于 RSIZE_MAX/sizeof(wchar_t)
編碼錯誤出現(xiàn)在任何字符串和字符轉(zhuǎn)換說明符中
(vswprintf_s
僅限于),要存儲的字符串buffer
(包括后面的寬空)將會超過bufsz
8)與(7)相同,除了它會截斷結(jié)果以適應s所指向的數(shù)組。由于所有的邊界檢查功能,vwprintf_s
,vfwprintf_s
,vswprintf_s
,和vsnwprintf_s
僅保證可供如果__STDC_LIB_EXT1__
由實現(xiàn)所定義,并且如果用戶定義__STDC_WANT_LIB_EXT1__
的整數(shù)常數(shù)1
,包括之前<wchar.h>
。
流 | - | 輸出寬流寫入 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
緩沖 | - | 指向要寫入的寬字符串的指針 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bufsz | - | 要寫入的最大寬字符數(shù) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
格式 | - | 指向以空字符結(jié)尾的寬字符串的指針,指定如何解釋數(shù)據(jù)。格式字符串由普通的寬字符(%除外)組成,它們被不變地復制到輸出流中,以及轉(zhuǎn)換規(guī)范。每個轉(zhuǎn)換規(guī)范具有以下格式:介紹%字符(可選)一個或多個標志,用于修改轉(zhuǎn)換的行為: - :轉(zhuǎn)換結(jié)果在字段內(nèi)左對齊(默認情況下,它是右對齊的)+ :帶符號轉(zhuǎn)換的符號總是作為轉(zhuǎn)換結(jié)果的前綴(默認情況下,只有當結(jié)果為負時,結(jié)果才以負值開頭)space:如果帶符號轉(zhuǎn)換的結(jié)果不是以符號字符開頭,或者是空的,空間是預先考慮的結(jié)果。如果存在+標志,則忽略它。#:執(zhí)行轉(zhuǎn)換的替代形式。請參閱下表以了解確切的效果,否則行為未定義。0:對于整數(shù)和浮點數(shù)轉(zhuǎn)換,前導零用于填充字段而不是空格字符。對于整數(shù),如果明確指定了精度,它將被忽略。對于使用此標志的其他轉(zhuǎn)換會導致未定義的行為。如果 - 標志存在,它將被忽略。(可選)整數(shù)值或*指定最小字段寬度。如果需要,結(jié)果會填充空格字符(默認情況下),右側(cè)對齊時填充空白字符,左側(cè)填充右側(cè)填充。在使用*的情況下,寬度由類型為int的附加參數(shù)指定。如果參數(shù)的值是負值,那么結(jié)果是指定 - 標志和正字段寬度。(注意:這是最小寬度:該值從不被截斷。)(可選)。后跟整數(shù)或*,或者兩者都不指定轉(zhuǎn)換的精度。在使用*的情況下,精度由類型為int的附加參數(shù)指定。如果這個參數(shù)的值是負數(shù),它將被忽略。如果既不使用數(shù)字也不使用*,則精度取為零。請參閱下表以了解精確度的確切影響。(可選)長度修飾符,用于指定參數(shù)轉(zhuǎn)換格式說明符的大小以下格式說明符可用:轉(zhuǎn)換說明符說明參數(shù)類型長度修飾符hh(C99)。h(無)ll(C99)。j(C99)。z(C99)。t(C99)。L%寫文字%。完整的轉(zhuǎn)換規(guī)范必須是%%。不適用不適用不適用不適用不適用不適用不適用不適用不適用單個字符。該參數(shù)首先轉(zhuǎn)換為wchar_t,就好像通過調(diào)用btowc一樣。如果使用l修飾符,則首先將wint_t參數(shù)轉(zhuǎn)換為wchar_t。N / AN / A int wint_t N / AN / AN / AN / AN / A s寫入字符串參數(shù)必須是一個指向包含多字節(jié)字符序列的字符數(shù)組的初始元素的指針,該字符序列從初始轉(zhuǎn)換狀態(tài)開始,被轉(zhuǎn)換為寬字符數(shù)組,就像通過調(diào)用mbrtowc以零初始化轉(zhuǎn)換狀態(tài)一樣。Precision指定要寫入的最大寬字符數(shù)。如果未指定Precision,則將每個寬字符寫入并不包括第一個空終止符。如果使用l說明符,參數(shù)必須是指向wchar_t數(shù)組的初始元素的指針。N / AN / A char * wchar_t * N / AN / AN / AN / AN / A di將有符號整數(shù)轉(zhuǎn)換為十進制表示形式-dddd。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。signed char short int long long long intmax_t signed size_t ptrdiff_t不適用o將無符號整數(shù)轉(zhuǎn)換為八進制表示oooo。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。在替代實現(xiàn)中,如果需要,可以增加精度以寫入一個前導零。在這種情況下,如果轉(zhuǎn)換值和精度均為0,則寫入單個0。unsigned char unsigned short unsigned int unsigned long unsigned long long uintmax_t size_t ptrdiff_t的無符號版本不適用x X將無符號整數(shù)轉(zhuǎn)換為十六進制表示形式hhhh。對于x轉(zhuǎn)換字母abcdef被使用。對于X轉(zhuǎn)換字母使用ABCDEF。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。在替代實現(xiàn)中,如果轉(zhuǎn)換后的值為非零值,則0x或0X將作為結(jié)果的前綴。不適用u將無符號整數(shù)轉(zhuǎn)換為十進制表示形式dddd。精度指定出現(xiàn)的最小位數(shù)。默認精度為1。如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成字符。N / A f F將浮點數(shù)轉(zhuǎn)換為樣式-ddd.ddd中的十進制表示法。精度指定小數(shù)點后面出現(xiàn)的最小位數(shù)。默認精度為6.在替代實現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點字符也會被寫入。對于無限和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。N / AN / A double double(C99)N / AN / AN / AN / A long double e E將浮點數(shù)轉(zhuǎn)換為十進制指數(shù)表示法。對于e轉(zhuǎn)換樣式,使用-d.ddde±dd。對于E轉(zhuǎn)換樣式,使用-d.dddE±dd。指數(shù)至少包含兩位數(shù)字,只有在必要時才使用更多數(shù)字。如果該值為0,則指數(shù)也為0。精度指定小數(shù)點后面出現(xiàn)的最小位數(shù)。默認精度為6.在替代實現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點字符也會被寫入。對于無限和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。不適用不適用不適用不適用不適用不適用(C99)。將浮點數(shù)轉(zhuǎn)換為十六進制指數(shù)表示法。對于轉(zhuǎn)換類型,使用-0xh.hhhp±d。對于A轉(zhuǎn)換樣式,使用-0Xh.hhhP±d。如果參數(shù)不是標準化的浮點值,則第一個十六進制數(shù)字為0。如果該值為0,則指數(shù)也為0。精度指定小數(shù)點后面出現(xiàn)的最小位數(shù)。默認精度足以精確表示值。在替代實現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點字符也會被寫入。對于無限和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。不可用/不可用/不可用/不可用/ g G根據(jù)值和精度將浮點數(shù)轉(zhuǎn)換為十進制或十進制指數(shù)符號。對于使用樣式e或f的g轉(zhuǎn)換樣式轉(zhuǎn)換將被執(zhí)行。對于G轉(zhuǎn)換樣式,將使用樣式E或F進行轉(zhuǎn)換。假設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ù)點字符也會被刪除。對于無限和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用 結(jié)果寫入?yún)?shù)指向的值。規(guī)范可能不包含任何標志,字段寬度或精度。signed char * short * int * long * long long * intmax_t * signed size_t * ptrdiff_t * N / A p寫一個實現(xiàn)定義的字符序列來定義一個指針。不適用不適用不適用不適用不適用不適用不適用浮點轉(zhuǎn)換函數(shù)將無窮大轉(zhuǎn)換為inf或無窮大。使用哪一個是實現(xiàn)定義的。非數(shù)字轉(zhuǎn)換為南或南(char_sequence)。使用哪一個是實現(xiàn)定義的。轉(zhuǎn)換F,E,G,A代替輸出INF,INFINITY,NAN。盡管%c需要int參數(shù),但因為在調(diào)用可變參數(shù)函數(shù)時發(fā)生整數(shù)提升,所以傳遞char是安全的。固定寬度字符類型(int8_t等)的正確轉(zhuǎn)換規(guī)范在標頭<inttypes.h>中定義(盡管PRIdMAX,PRIuMAX等與%jd,%ju等同義)。內(nèi)存寫入轉(zhuǎn)換說明符%n是格式字符串依賴用戶輸入并且不受邊界檢查的printf_s系列函數(shù)支持的安全漏洞的常見目標。每個轉(zhuǎn)換說明符的操作之后都有一個序列點; 這允許將多個%n結(jié)果存儲在相同的變量中,或者,作為邊緣情況,在相同的調(diào)用中打印由早先的%n修改的字符串。如果轉(zhuǎn)換規(guī)范無效,則行為未定義。 | 轉(zhuǎn)換說明符 | 說明 | 參數(shù)類型 | 長度修飾符 | hh(C99)。 | H | (沒有) | 升 | (C99)。 | j(C99)。 | 來自(C99)。 | t(C99)。 | 該 | % | 寫文字%。完整的轉(zhuǎn)換規(guī)范必須是%%。 | N / A | N / A | N / A | N / A | N / A | N / A | N / A | N / A | N / A | C | 寫一個字符。該參數(shù)首先轉(zhuǎn)換為wchar_t,就像調(diào)用btowc一樣。如果使用l修飾符,則首先將wint_t參數(shù)轉(zhuǎn)換為wchar_t。 | N / A | N / A | INT | 所述wint_t | N / A | N / A | N / A | N / A | N / A | 小號 | 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 | 寫入字符串參數(shù)必須是指向包含從初始移位狀態(tài)開始的多字節(jié)字符序列的字符數(shù)組的初始元素的指針,該字符序列將轉(zhuǎn)換為寬字符數(shù)組,就好像通過調(diào)用mbrtowc進行零初始化轉(zhuǎn)換狀態(tài)。Precision指定要寫入的最大寬字符數(shù)。如果未指定Precision,則將每個寬字符寫入并不包括第一個空終止符。如果使用l說明符,則參數(shù)必須是指向wchar_t數(shù)組的初始元素的指針。 | N / A | N / A | 字符* | wchar_t的* | N / A | N / A | N / A | N / A | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迪 | 將有符號的整數(shù)轉(zhuǎn)換為十進制表示形式-dddd。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。 | 簽名字符 | 短 | INT | long | 漫長的 | 還會將intmax_t | 簽名size_t | ptrdiff_t的 | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
該 | 將無符號整數(shù)轉(zhuǎn)換為八進制表示oooo。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。在替代實現(xiàn)中,如果需要,可以增加精度以寫入一個前導零。在這種情況下,如果轉(zhuǎn)換值和精度均為0,則寫入單個0。 | 無符號字符 | 無符號短 | 無符號整數(shù) | 無符號長整數(shù) | 無符號long long | uintmax_t型 | 為size_t | 未簽名的ptrdiff_t版本 | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x X | 將無符號整數(shù)轉(zhuǎn)換為十六進制表示hhhh。對于x轉(zhuǎn)換字母abcdef被使用。對于X轉(zhuǎn)換字母使用ABCDEF。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。在替代實現(xiàn)中,如果轉(zhuǎn)換后的值為非零值,則0x或0X將作為結(jié)果的前綴。 | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
在 | 將無符號整數(shù)轉(zhuǎn)換為十進制表示形式dddd。精度指定出現(xiàn)的最小位數(shù)。默認精度為1.如果轉(zhuǎn)換值和精度均為0,則轉(zhuǎn)換不會生成任何字符。 | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f | 將浮點數(shù)轉(zhuǎn)換為樣式-ddd.ddd中的小數(shù)表示法。精度指定小數(shù)點后面出現(xiàn)的最小位數(shù)。默認精度為6.在替代實現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點字符也會被寫入。對于無窮大和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。 | N / A | N / A | 雙 | 雙(C99) | N / A | N / A | N / A | N / A | 長雙 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
和E | 將浮點數(shù)轉(zhuǎn)換為十進制指數(shù)符號。對于e轉(zhuǎn)換樣式,使用-d.ddde±dd。對于E轉(zhuǎn)換樣式,使用-d.dddE±dd。指數(shù)至少包含兩位數(shù)字,只有在必要時才使用更多數(shù)字。如果該值為0,則指數(shù)也為0。精度指定小數(shù)點后面出現(xiàn)的最小位數(shù)。默認精度為6.在替代實現(xiàn)中,即使沒有數(shù)字跟隨,小數(shù)點字符也會被寫入。對于無窮大和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A(C99)。 | 將浮點數(shù)轉(zhuǎn)換為十六進制指數(shù)表示法。對于轉(zhuǎn)換類型,使用-0xh.hhhp±d。對于A轉(zhuǎn)換樣式,使用-0Xh.hhhP±d。如果參數(shù)不是標準化的浮點值,則第一個十六進制數(shù)字為0。如果該值為0,則指數(shù)也為0。精度指定小數(shù)點后面出現(xiàn)的最小位數(shù)。默認精度足以精確表示值。在替代實現(xiàn)中,即使沒有數(shù)字跟隨它,也會寫入小數(shù)點字符。對于無窮大和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
g G | 根據(jù)值和精度將浮點數(shù)轉(zhuǎn)換為十進制或十進制指數(shù)符號。對于使用樣式e或f的g轉(zhuǎn)換樣式轉(zhuǎn)換將被執(zhí)行。對于G轉(zhuǎn)換樣式,將使用樣式E或F進行轉(zhuǎn)換。假設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ù)點字符也會被刪除。對于無窮大和非數(shù)字轉(zhuǎn)換風格,請參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? | 將此調(diào)用到目前為止寫入的字符數(shù)返回給該函數(shù)。結(jié)果寫入?yún)?shù)指向的值。規(guī)范可能不包含任何標志,字段寬度或精度。 | 簽名字符* | 短* | INT * | long* | 很長* | *將intmax_t | 簽名size_t * | ptrdiff_t的* | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p | 寫一個實現(xiàn)定義的字符序列來定義一個指針。 | N / A | N / A | 無效* | N / A | N / A | N / A | N / A | N / A | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VLIST | - | 包含要打印的數(shù)據(jù)的變量參數(shù)列表 |
1-3)如果發(fā)生錯誤,則成功寫入寬字符數(shù)或?qū)懭雽捵址麛?shù)。
4)如果發(fā)生錯誤,則成功寫入寬字符數(shù)或?qū)懭雽捵址麛?shù)。如果由于bufsz
限制而導致結(jié)果字符串被截斷,則函數(shù)將返回如果未強加限制,則會寫入的字符總數(shù)(不包括終止空寬字符)。
5,6)傳輸?shù)捷敵隽鞯膶捵址麛?shù),如果發(fā)生輸出錯誤,運行時約束違規(guī)錯誤或編碼錯誤,則輸出負值。
7)寫入的寬字符數(shù)buffer
,不包括空寬字符(只要buffer
不是空指針,bufsz
且不為零且不大于RSIZE_MAX/sizeof(wchar_t)
),則為空寬字符,或者在運行時約束違規(guī)時為零,并且編碼為負值錯誤
8)不包括終止空字符的寬字符數(shù)(只要buffer
不是空指針bufsz
且不為零且不大于RSIZE_MAX/sizeof(wchar_t)
),buffer
如果bufsz
被忽略,則寫入的寬字符數(shù)或負值if發(fā)生運行時約束違規(guī)或編碼錯誤
所有這些函數(shù)va_arg
至少調(diào)用一次,arg
返回后的值是不確定的。這些函數(shù)不會調(diào)用va_end
,并且它必須由調(diào)用者完成。
雖然窄字符串提供了vsnprintf
,這使得可以確定所需的輸出緩沖區(qū)大小,但對于寬字符串沒有等效(直到C11的vsnwprintf_s),并且為了確定緩沖區(qū)大小,程序可能需要調(diào)用vswprintf
,檢查結(jié)果值,并重新分配一個更大的緩沖區(qū),再次嘗試直到成功。
vsnwprintf_s
不同vswprintf_s
,將截斷結(jié)果以適應指向的數(shù)組buffer
,即使截斷被大多數(shù)邊界檢查函數(shù)視為錯誤。
#include <stdio.h>#include <time.h>#include <locale.h> void debug_wlog(const wchar_t *fmt, ...){ struct timespec ts; timespec_get(&ts, TIME_UTC); char time_buf[100]; size_t rc = strftime(time_buf, sizeof time_buf, "%D %T", gmtime(&ts.tv_sec)); snprintf(time_buf + rc, sizeof time_buf - rc, ".%06ld UTC", ts.tv_nsec / 1000); va_list args; va_start(args, fmt); wchar_t buf[1000]; int rc2 = vswprintf(buf, sizeof buf / sizeof *buf, fmt, args); va_end(args); if(rc2 > 0) wprintf(L"%s [debug]: %ls\n", time_buf, buf); else wprintf(L"%s [debug]: (string too long)\n", time_buf);} int main(void){ setlocale(LC_ALL, ""); debug_wlog(L"Logging, %d, %d, %d", 1, 2, 3);}
可能的輸出:
02/20/15 22:12:38.476575 UTC [debug]: Logging, 1, 2, 3