Share via


argument of type "const char*" is incompatible with parameter of type "const wchar_t*"

Question

Monday, August 13, 2018 8:25 AM

Hi,

When i am compiling my project at the below line i am getting the error **"argument of type "const char*" is incompatible with parameter of type "const wchar_t*" **

_stprintf (thePathname, "%s\%s", lpszResPath, _theResDllname);

when i changed the 2nd parameter with either of the below it is not showing any error message.

L"%s\%s"

_T("%s\%s")

From Microsoft forums, i understood that

_T("Text") is a narrow-character (ASCII) literal in an ANSI build but a wide character (UNICODE) literal in a Unicode build.

L"Text" is always a wide-character literal, regardless of preprocessor definitions.

_T() is a macro, the L prefix is part of the core C and C++ language lexical structure.

My project is configured with Character Set "Unicode Character Set", So, Can i go with using L"%s\%s".

Regards,

Satya

All replies (1)

Monday, August 13, 2018 8:38 AM âś…Answered

Hi,

When i am compiling my project at the below line i am getting the error **"argument of type "const char*" is incompatible with parameter of type "const wchar_t*" **

_stprintf (thePathname, "%s\%s", lpszResPath, _theResDllname);

when i changed the 2nd parameter with either of the below it is not showing any error message.

L"%s\%s"

_T("%s\%s")

From Microsoft forums, i understood that

_T("Text") is a narrow-character (ASCII) literal in an ANSI build but a wide character (UNICODE) literal in a Unicode build.

L"Text" is always a wide-character literal, regardless of preprocessor definitions.

_T() is a macro, the L prefix is part of the core C and C++ language lexical structure.

My project is configured with Character Set "Unicode Character Set", So, Can i go with using L"%s\%s".

Regards,

Satya

In *sprintf functions, you must use UNICODE because your project is UNICODE. So either use L".." or _T("..").

If you want to stay flexible with the character set, you should use _T() and the  TCHAR routines.

Regards, Guido