函式
<cwchar>

wprintf

int wprintf (const wchar_t* format, ...);
將格式化資料列印到標準輸出
format 指向的 C 寬字串寫入標準輸出 (stdout),並以與 printf 相同的方式替換任何格式說明符

寬字元在stdout中的外部表示是多位元組字元:這些字元是透過呼叫 wcrtomb 來轉換每個寬字元而獲得的(使用的內部 mbstate_t 物件)。

這是 printf (<cstdio>) 的寬字元等效版本。

引數

format
C 寬字串,包含一個格式字串,其遵循與 printfformat 相同的規範(詳情請參閱 printf)。
請注意,所有格式說明符的含義與 printf 中相同;因此,%lc應用於寫入一個寬字元(而不是%c),同樣%ls應用於寬字串(而不是%s).
... (附加引數)
根據格式字串,函式可能需要一系列附加引數,每個引數包含一個用於替換格式字串中格式說明符的值(或者,對於n).
,是指向儲存位置的指標)。這些引數的數量應至少與格式說明符中指定的值的數量一樣多。額外的引數會被函式忽略。

返回值

成功時,返回寫入的字元總數。

如果發生寫入錯誤,則會設定錯誤指示符ferror)並返回一個負數。

如果在寫入寬字元時發生多位元組字元編碼錯誤,errno 會被設定為EILSEQ並返回一個負數。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* wprintf example */
#include <wchar.h>

int main()
{
   wprintf (L"Characters: %lc %lc \n", L'a', 65);
   wprintf (L"Decimals: %d %ld\n", 1977, 650000L);
   wprintf (L"Preceding with blanks: %10d \n", 1977);
   wprintf (L"Preceding with zeros: %010d \n", 1977);
   wprintf (L"Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
   wprintf (L"floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
   wprintf (L"Width trick: %*d \n", 5, 10);
   wprintf (L"%ls \n", L"A wide string");
   return 0;
}

輸出

Characters: a A
Decimals: 1977 650000
Preceding with blanks:       1977
Preceding with zeros: 0000001977
Some different radixes: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick:    10
A wide string


另見