开发者

Implicit convert CString to char*

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 开发者_StackOverflow社区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*


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).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜