[英]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变量作为char *传递给sscanf()函数,编译器隐式转换那些CString并且代码编译正常。这里的代码工作正常:
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* 当我试图编写我自己的简单代码试图以相同的方式操纵CString变量但编译器说不能将CString转换为cahr时问题就在这里
I suspect that your own code is using unicode ( UNICODE
constant defined). 我怀疑你自己的代码使用的是unicode( UNICODE
常量定义)。 This means that CString
is using wide characters, and will implicitly convert to wchar_t*
, but not to char*
. 这意味着CString
使用宽字符,并将隐式转换为wchar_t*
,但不会转换为char*
。
If that is the case, there are three possible solutions: 如果是这种情况,有三种可能的解决方案:
swscanf
, the wide character version of sscanf
(recommended); 使用swscanf
, sscanf
的宽字符版本(推荐); CStringA
instead of CString
so you're using the ANSI version of CString
; 明确使用CStringA
而不是CString
因此您使用的是CString
的ANSI版本;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.