0

I have downloaded an sample code, so there are some CString variables in that code which are passed to the sscanf() function as char* the compiler implicitly converts those CString and the code complie fine.the code which works fine is here:

CString m_strVersionXFS;
m_strVersionXFS = _T("00029903");

DWORD nVersion;
sscanf(m_strVersionXFS,"%08X",&nVersion);

the problem is here when i tried to write my own simple code which tries to manipulate a CString variable in the same way but the compiler says which can't convert a CString to a cahr*

1
  • just some minor correction: It is const char*, not char*. You can't make it non-const. Commented Aug 8, 2011 at 7:06

1 Answer 1

3

I suspect that your own code is using unicode (UNICODE constant defined). This means that CString is using wide characters, and will implicitly convert to wchar_t*, but not to char*.

If that is the case, there are three possible solutions:

  1. Use swscanf, the wide character version of sscanf (recommended);
  2. Explicitly use CStringA instead of CString so you're using the ANSI version of CString;
  3. Change your project to use multi-byte characters rather than unicode (this can be done from the project properties in Visual Studio).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.