VC++6.0关于MFC的编程中 error C2664问题
C++中调用CString类时老出现errorC2664错误,搞了好久没查出,求大侠指教!急!!!CStringunicode=YString::ChineseToUni...
C++中调用CString类时老出现error C2664错误,搞了好久没查出,求大侠指教!急!!!
CString unicode = YString::ChineseToUnicode(chinese); ————>错误处
错误提示:error C2664: 'ChineseToUnicode' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
ChineseToUnicode函数定义:
CString YString::ChineseToUnicode(LPCWSTR lpUnicode)
{
CString wcsResult;
unsigned char *pCh = (unsigned char *) lpUnicode;
int nCount = wcslen( lpUnicode );
for (unsigned int i = 0; i < nCount * sizeof(WCHAR); i += 2 )
{
CString wcsTemp;
wcsTemp.Format( _T("%02X%02X"), pCh[i+1], pCh[i] );
wcsResult += wcsTemp;
}
return wcsResult;
} 展开
CString unicode = YString::ChineseToUnicode(chinese); ————>错误处
错误提示:error C2664: 'ChineseToUnicode' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
ChineseToUnicode函数定义:
CString YString::ChineseToUnicode(LPCWSTR lpUnicode)
{
CString wcsResult;
unsigned char *pCh = (unsigned char *) lpUnicode;
int nCount = wcslen( lpUnicode );
for (unsigned int i = 0; i < nCount * sizeof(WCHAR); i += 2 )
{
CString wcsTemp;
wcsTemp.Format( _T("%02X%02X"), pCh[i+1], pCh[i] );
wcsResult += wcsTemp;
}
return wcsResult;
} 展开
2个回答
展开全部
按照提示,很明显是你实参带入错误啊,
CString YString::ChineseToUnicode(LPCWSTR lpUnicode)
这个形参应该是LPCWSTR,但是你带入的chinese这个实参应该是CString类型的,
所以才有cannot convert parameter 1 from 'class CString' to 'const unsigned short *'。
CString YString::ChineseToUnicode(LPCWSTR lpUnicode)
这个形参应该是LPCWSTR,但是你带入的chinese这个实参应该是CString类型的,
所以才有cannot convert parameter 1 from 'class CString' to 'const unsigned short *'。
追问
谢谢啦!这问题解决了,还有一个再麻烦你一下!
tmp.Insert(0, L"0");
error C2664: 'int __thiscall CString::Insert(int,char)' : cannot convert parameter 2 from 'unsigned short [2]' to 'char'
追答
tmp.Insert(0,'0'); 这样改,说的第二个参数是字符型,你还放个字符串进去,当然错误了。
你这个是什么意思?在最前边加上一个0?这是干嘛的?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询