代码:
//得到密文或原文
//bEncrypt:true 加密
        //:false 解密
CString CTools::GetPriString(CString buf,bool bEncrypt)
{
buf = buf.Trim();//trim()除去字符串开始和结尾的空格 if(buf =="")
return "";
CString str,temp;
char c;
int k;
if(bEncrypt)//加密
{
for(int i =0;i< buf.GetLength();i++)
{
c = buf.GetAt(i);
k = c ^ 0xCC;
temp.Format("%d",k);
str += temp;
str += ",";
}
str = str.Mid(0,str.GetLength() - 1 );
}
else //解密
{
int pos = buf.Find(",");
while( pos != -1)
{
temp = buf.Mid(0,pos).Trim();
k = atol( temp ) ^ 0xCC;//atol()将字符串转换成长整型
c = (char)k;
str += c;
buf = buf.Mid( pos + 1);
pos = buf.Find(",");
}
temp = buf.Trim();
 k = atol( temp ) ^ 0xBA;
 c = (char)k;
 str += c;
}
return str;
}
错误:error C2664: 'atol' : cannot convert parameter 1 from 'CString' to 'const char *'
error C2664: 'int ATL::CStringT<BaseType,StringTraits>::Find(wchar_t,int) throw() const' : cannot convert parameter 1 from 'const char [2]' to 'wchar_t'
注:红色部分出错

解决方案 »

  1.   

    CString CTools::GetPriString(CString buf,bool bEncrypt)
    {
    buf = buf.Trim();//trim()除去字符串开始和结尾的空格 if(buf =="")
    return "";
    CString str,temp;
    char c;
    int k;
    if(bEncrypt)//加密
    {
    for(int i =0;i< buf.GetLength();i++)
    {
    c = buf.GetAt(i);
    k = c ^ 0xCC;
    temp.Format("%d",k);
    str += temp;
    str += ",";
    }
    str = str.Mid(0,str.GetLength() - 1 );
    }
    else //解密
    {
    int pos = buf.Find(",");
    while( pos != -1)
    {
    temp = buf.Mid(0,pos).Trim();
    k = atol( temp ) ^ 0xCC;//报错
    c = (char)k;
    str += c;
    buf = buf.Mid( pos + 1);//报错
    pos = buf.Find(",");
    }
    temp = buf.Trim();
    // k = atol( temp ) ^ 0xBA;//报错
     c = (char)k;
     str += c;
    }
    return str;
    }