By default a Windows app is set to use 16-bit characters, not 8-bit characters. Change your quoted string to L"%d %" to specify a string of 16-bit characters.
cannot convert parameter 1 from 'const char [6]' to 'const wchar_t *
Question
I'm new to MFC and I don't know what to do with this error.
ERROR
error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [6]' to 'const wchar_t *'
heres the line:
m_Echo1.Format("%d %",state.dwMemoryLoad);
Solution
OTHER TIPS
There are 2 distinct errors with the line of code you posted:
- The format string contains an illegal format specifier (trailing
%
). If you want a format string to contain a literal percent-sign it has to be escaped using%%
. - You are using a string literal that does not match the required encoding, i.e. a mismatch between ANSI and UNICODE character encoding. If
m_Echo1
is of typeCString
the parameter has to be wrapped inside a_T
orTEXT
macro:_T( "%d %%" )
. Ifm_Echo1
is of typeCStringW
the parameter must be passed as a UNICODE string literal by prepending it withL
:L"%d %%"
.
Note: The error message you posted does not match the line of code. The error message refers to const char [6]
while the string literal in your code is of type const char [5]
. Make sure that error messages and code match up.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow