Note that from swprintf of MSDN:
swprintf is a wide-character version of sprintf; the pointer arguments to swprintf are wide-character strings.
and then in the example:
wchar_t buf[100];
int len = swprintf( buf, 100, L"%s", L"Hello world" );
so at least Microsoft documented this.
And then in the page of format specifiers
s String When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached.
And then
S String When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte–character string. Characters are printed up to the first null character or until the precision value is reached.
So what you want is upper-case %S
.
See even this similar question: visual studio swprintf is making all my %s formatters want wchar_t * instead of char * where they suggest using %ls
(always consider the parameter wchar_t*
) and %hs
(always consider the parameter char*
)