Unicode strings with printf
Useful tip for other techies out there: I just discovered that printf(”%ls”, (wchar_t pointer goes here)) prints out wide strings. Nice! At least, it does for MinGW.
Useful tip for other techies out there: I just discovered that printf(”%ls”, (wchar_t pointer goes here)) prints out wide strings. Nice! At least, it does for MinGW.
February 14th, 2007 at 6:05 pm
I believe also that the format string “%S” is synonymous with “%ls”.
In Microsoft’s runtime library at least, wprintf(”%S”, …) behaves symmetrically and will print a single-byte-character string into the resulting wide string output.
If you’ve ever had the misfortune to work with TCHAR strings, then you may see a dilema here:
_tprintf(_T(”%s”), ptr) allows you put a TCHAR* into the resulting TCHAR output. So what is the type of ptr in the expression _tprintf(_T(”%S”), ptr) ?
!TCHAR ?
February 14th, 2007 at 6:06 pm
That should of course be
wprintf(L”%S”, …)
and not
wprintf(”%S”, …)
Enough geekery!