c++ Ansi和Unicode相互转换

int Ansi_To_Unicode(string strSrc, wstring& strRet)
{
  wchar_t wBuff[102400] = { 0 };
  CHAR sBuff[102400] = { 0 };
  int iRet = MultiByteToWideChar(CP_ACP, 0, strSrc.c_str(), -1, wBuff, 102400);
  if (iRet > 0) {
    strRet = wBuff;
    return TRUE;
  }
  return FALSE;
}

int Unicode_To_Ansi(wstring strValue, string& strRet)
{
  CHAR sBuff[102400] = { 0 };
  int iRet = WideCharToMultiByte(CP_ACP, 0, strValue.c_str(), -1, sBuff, 102400, NULL, NULL);
  if (iRet > 0) {
    strRet = sBuff;
    return TRUE;
  }
  return FALSE;
}

posted @ 2020-11-04 22:37  龙马8586  阅读(944)  评论(0编辑  收藏  举报