linux c++下gb18030、utf8之间的转换

int nSrcLen;
int nDestLen;
char szConvertBuf[4096] ={0};
char szMess[256] ={0};
nSrcLen = strlen(str);
nDestLen = 256;
if(-1 == ConverCode("GB18030", "UTF-8", str,(size_t)nSrcLen, szConvertBuf, (size_t)nDestLen, szMess))
{
    retcode=-1;
    sprintf(m_errMsg, "字符转化失败,[%s]",szMess);
    m_logger.WriteLog(Err,__LINE__,m_reqNo,RETCODE_SYSTEM,m_errMsg);
    return string(szMess);
}
sprintf(m_errMsg, "字符转化成功,[%s]",szConvertBuf);
m_logger.WriteLog(Detail,__LINE__,m_reqNo,RETCODE_SYSTEM,m_errMsg);
retcode=0;
return string(szConvertBuf);
}

string CHostFunc::UTF8ToGB(const char* str,int &retcode)
{
int nSrcLen;
int nDestLen;
char szConvertBuf[4096] ={0};
char szMess[256] ={0};
nSrcLen = strlen(str);
nDestLen = 256;
if(-1 == ConverCode("UTF-8", "GB18030", str,(size_t)nSrcLen, szConvertBuf, (size_t)nDestLen, szMess))
{
    retcode =-1;
     sprintf(m_errMsg, "字符转化失败,[%s]",szMess);
    m_logger.WriteLog(Err,__LINE__,m_reqNo,RETCODE_SYSTEM,m_errMsg);
    return string(szMess);
}
sprintf(m_errMsg, "字符转化成功,[%s]",szConvertBuf);
m_logger.WriteLog(Detail,__LINE__,m_reqNo,RETCODE_SYSTEM,m_errMsg);
    retcode=0;
return string(szConvertBuf);

你可能感兴趣的:(Unix/Linux,C/C++)