Narrow-line swprintf ()

The following line of code gives trash with Visual Studio 2010:

swprintf(buf, L"Value is %s", "abcd");

However, the same code works fine on Linux.

During the trial version, I could get it to work using% S instead of% s in Visual Studio.

swprintf(buf, L"Value is %s", "abcd");

I am wondering if this is a bug in Visual Studio 2010, or am I missing something. Regards.

+4
source share
4 answers

This is a "mistake", although the design behavior. The initial implementation of Visual C ++ for large printf and scanf functions preceded their standardization in C, and in some cases the behavior deviates from what is required in the specification of the standard C library.

C %s %c char, l , wchar_t .

Visual ++ () %s %c "" . printf scanf char, wchar_t. "" , %s %c. , h l , .

Visual ++ Unicode _TCHAR <tchar.h>. , , Visual ++ ( , , .).

+4

Microsoft printf scanf , Linux (-) Windows ().

, , MSDN, :

C, S Z c s, printf wprintf, Microsoft ANSI . Visual ++ F.

. BTW: ANSI C, ++.

, MS (c s), UTF-16 .

+3

% s % S :

s: printf ; wprintf . .

S: printf ; wprintf . .

swprintf(buf, L"Value is %S", "abcd");

.

MSDN .

0

"abcd" , "L". swprintf() , % s .

0

Source: https://habr.com/ru/post/1539967/


All Articles