C++官网参考链接:https://cplusplus.com/reference/cwchar/wprintf/
函数
wprintf
int wprintf (const wchar_t* format, ...);
将格式化的数据打印到标准输出
将按format指向的C宽字符串写入标准输出(stdout),以与printf相同的方式替换任何格式说明符。
在stdout中宽字符的外部表示形式是多字节字符:就像调用wcrtomb来转换每个宽字符(使用流的内部mbstate_t对象)一样获得这些多字节字符。
这是printf(
形参
format
C宽字符串,包含一个格式字符串,该格式字符串遵循与printf中的format相同的规范(详细信息请参阅printf)。
注意,所有格式说明符的含义都与printf中的含义相同;因此,%lc应用于写宽字符(而不是%c),%ls应用于写宽字符串(而不是%s)。
...(附加实参)
根据format字符串的不同,函数可能需要一系列附加实参,每个实参包含一个值,用于替换format字符串中的格式说明符(对于n指向存储位置的指针)。
这些实参的数量至少应该与格式说明符中指定的值的数量相同。函数将忽略额外的实参。
返回值
如果成功,则返回写入的字符总数。
如果发生写错误,则设置错误指示符(ferror)并返回负数。
如果在写入宽字符时发生多字节字符编码错误,则errno设置为EILSEQ并返回负数。
用例
/* wprintf example */
#include
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;
}
输出:
