Visual studio swprintf does all my% s formatters want wchar_t * instead of char *

Ive got a multi-platform project that compiles fine on a Mac, but in windows all my calls to swprintf with% s look for wchar_t instead of char * im sending it. It turns out that M $ thought it would be funny to do% s for something other than char * in wide character functions ... http://msdn.microsoft.com/en-us/library/hf4y5e3w.aspx

In any case, I am looking for a creative coding trick that is better than putting an ifdef, otherwise it ends up around every broadcast call

+5
source share
3 answers

Visual Studio 14 CTP1 %s (char*), _CRT_STDIO_LEGACY_WIDE_SPECIFIERS. T, , MS "" . sprintf %Ts char*, swprintf %Ts - wchar_t*.


Visual Studio 13 %s/%c /, %s/%c :

printf("%c %C %s %S\n", 'a', L'B', "cd", L"EF");
wprintf(L"%c %C %s %S\n", L'a', 'B', L"cd", "EF");

: %ls, %lc, %ws %wc wchar_t %hs %hc char. ( VS2003 VC6 ( %ws ))

%s Win9x WinNT, tchar.h header . _UNICODE , tchar.h , TCHAR - wchar_t, , TCHAR - char:

_tprintf(_T("%c %s\n"), _T('a'), _T("Bcd"));

, Windows SDK , (wsprintf, wvsprintf, wnsprintf wvnsprintf), UNICODE TEXT, _UNICODE _T/_TEXT.

, , 3 , Windows, Windows:

1) Windows, , , swprintf % s wchar_t *.

2) , , inttypes.h:

#ifdef _WIN32
#define PRIs "s"
#define WPRIs L"hs"
#else
#define PRIs "s"
#define WPRIs L"s" 
#endif
printf("%" PRIs " World\n", "Hello");
wprintf(L"%" WPRIs L" World\n", "Hello");

3) swprintf Visual Studio 13 .

+4

%ls, wchar_t*.

+2

You can use the format specifier "% Ts", or you can define _CRT_STDIO_LEGACY_WIDE_SPECIFIERS = 1.

Read this:

http://blogs.msdn.com/b/vcblog/archive/2014/06/18/crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1.aspx

+2
source

All Articles