CString strtemp = _T("31")
Messagebox(strtemp);怎样进行数据转换能使输出的值为31对应的ASCIi值 1 呢?

解决方案 »

  1.   

    char temp = atoi(strtemp.GetBuffer(0));
      

  2.   

    输出用CString 。该怎么做呢?
      

  3.   

    int iValue = atoi("31");
    char szMsg[2] = {0};sprintf(szMsg, "%c", (char)iValue);
    Messagebox(szMsg);
      

  4.   


    CString = “313233”
    怎样能输出123呢
      

  5.   

    int Ascii2Char(const CString & sStr, CString &sOutput)
    {
      char *p = (LPCTSTR)sStr;
      char szTmp[3];
      int iValue;
      char szMsg[2] = {0};
      sOutput = "";
      while(*p && *(p + 1))
      {
        strncpy(szTmp, p, 2);
        iValue = atoi(szTmp);
        sprintf(szMsg, "%c", (char)iValue);
        sOutput += szMsg;
        p += 2;
      }  return sOutput.GetLength();}
      

  6.   


    不能。
    31变成ASCII时变成13
      

  7.   


    CString strtemp = _T("313233");
    CString strResult;
    int nasc = 0;
    for(int i=0; i<strtemp.GetLength(); i=i+2)
    {
    CString strMid = strtemp.Mid(i,2);
    swscanf(strMid,L"%02x",&nasc);
    strMid.Format(L"%c",nasc);
    strResult = strResult + strMid;
    }

    AfxMessageBox(strResult);
      

  8.   


    CString Asc2Str(CString strSrc)
    {
       LPSTR *pszDest = new char[(strSrc.GetLength() + 3) / 2];
       LPSTR *p = pszDest;#define _ASC2BIN(x) (((x) <= _T('9')) ? (x)-_T('0') : (((x) <= _T('F')) ? (x)-_T('A')+10 : (x)-_T('a')+10))
       int i = 0;
       while(strSrc[i] != 0 && strSrc[i+1] != 0) {
          *p++ = (_ASC2BIN(strSrc[i]) << 4) + _ASC2BIN(strSrc[i+1]);
          i += 2;
       }
       *p = 0;
    #undef _ASC2BIN   CString strDest = pszDest;
       delete [] pszDest;
       return strDest;
    }
      

  9.   


    int Ascii2Char(CString& strIn, CString& strOut)
    {
    if(strIn.IsEmpty())
    {
    AfxMessageBox(_T("Error!"));
    return -1;
    }
    strOut.Empty();
    int len = strIn.GetLength();
    int i=0;
    for(i=0; i<len; i++)
    {
    TCHAR ch = strIn.GetAt(i);
    if(ch < _T('0') || ch > _T('9'))
    {
    AfxMessageBox(_T("Error!"));
    return -1;
    }
    } CString strTmp(_T(""));
    for(i=0; i<len; i+=2)
    {
    strTmp = strIn.Mid(i, 2);
    strTmp.Format(_T("%c"), _tcstoul(strTmp, NULL, 16));
    strOut += strTmp;
    }
    return 0;
    }
      

  10.   

    我重新写了一下:CString strtemp,strtemp1;
    char chartemp[200];
    for (int i=0;i<m_comdata.GetLength()/2;i++)

    CString strMid =m_comdata.Mid(i*2);
    sscanf(strMid,"%02X",(chartemp+i));
    }帮忙看看这两者有什么区别吗?