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);
Was it helpful?

Solution

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.

OTHER TIPS

There are 2 distinct errors with the line of code you posted:

  1. 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 %%.
  2. 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 type CString the parameter has to be wrapped inside a _T or TEXT macro: _T( "%d %%" ). If m_Echo1 is of type CStringW the parameter must be passed as a UNICODE string literal by prepending it with L: 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
scroll top