C 程式設計/stdio.h/wprintf
外觀
(從 C 程式設計/C 參考/stdio.h/wprintf 重定向)
wprintf是一個 C 標準庫函式,定義在 wchar.h 中。它的函式簽名是
int wprintf(const wchar t *format,...);
wprintf() 將輸出寫入 stdout,即標準輸出流。它使用可變引數列表。此函式以及 vprintf、vfprintf、vsprintf、vsnprintf 和 vasprintf 等函式使程式設計師能夠實質上建立自己的 printf 變體。
wprintf 函式在 C 中被發現,它在格式字串的控制下將輸出寫入流。格式字串指定後續引數如何轉換為輸出。
wprintf 是 printf 格式的寬字元版本。格式是一個寬字元字串,其中 wprintf 和 printf 在以 ANSI 模式開啟時行為類似。
以下是瞭解 wprintf 工作原理的示例程式碼。
程式碼
#include<stdio.h>
#include<wchar.h>
int main(int argc,char *argv[])
{
wchar_t *str = L"@TAJMAHAL@#$$$";
wprintf(L"%ls\n", str);
return EXIT_SUCCESS;
}
執行程式碼後,輸出將如下所示
@TAJMAHAL@#$$$
限制
1. wprintf() 不是可移植函式。
2. wprintf() 不能與 printf() 混合使用。
3. wprintf 不能列印雙精度值。
for eg. 2^56 is the double value which cannot be printed using wprintf().