#C 语言标准库函数 swprintf
#include <wchar.h>
int swprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict format, ...);
说明
按格式向宽字符数组写出数据。
按照格式说明提供参数,转换以当前 locale 的相应规则为准。
当空间不足时返回负值,不能通过 n 为 0 查询容量。
自 C95 起提供。
参数
s- 接收输出的可写宽字符数组。n- 输出数组容量,按宽字符计,包含终止符。format- 以空字符结束的格式串,包含普通字符和转换指令。...- 随转换指令提供的输出值。
返回值
- 正常返回实际写出宽字符数,排除终止符。输出或编码错误时返回负值。
#示例
#include <wchar.h>
int main(void)
{
wchar_t text[32];
int count = swprintf(text, sizeof text / sizeof text[0], L"item %d\n", 42);
return count != 8;
}