前者很常用, 经常被用来转换为字符串或者拼接字符串。
例子:
#include <Windows.h> #include <stdio.h> int main() { int t = 123456; WCHAR str[256] = L"heelo"; wsprintf(&str[5], L"%d", t); wprintf(L"%s", str); return 0; }
结果:
heelo123456
也可以与OutputDebugString配合使用,
WCHAR printData[100]; wsprintf(printData, L" Event: %d ", meEvent); OutputDebugString(printData);
wvsprintf函数很少见, 下面的例子供参考
#include <Windows.h> #include <stdio.h> void panic(const wchar_t* fmt, ...) { wchar_t buffer[1024]; va_list args = NULL; va_start(args, fmt); wvsprintfW(buffer, fmt, args); va_end(args); MessageBoxW(NULL, buffer, L"error", MB_OK | MB_ICONERROR); ExitProcess(EXIT_FAILURE); } int main() { panic(L"hello, %s!", L"michael"); return 0; }
结果: