我想得到"中"的ascii值,不知道有没有这样的函数?请指教,谢谢。

解决方案 »

  1.   

    just read the value of the bytes
      

  2.   

    how do you want to use it?
      

  3.   

    #include "stdafx.h"
    #include "stdio.h"
    #include "string.h"
    void main()
    {
    unsigned char szString[] = "中";
    for (unsigned int i=0;i<strlen((char*)szString);i++)
    {
    printf("%02x ",szString[i]);
    }
    }/*
    程序运行结果:
    d6 d0
    */
      

  4.   

    char w[3] = "我";
    short *p;
    p = (short *)w;
    CString msg;
    msg.Format("%d",*p);
    AfxMessageBox(msg);
    the anwser is -11570;
      

  5.   

    to denis95(denis95) :
       谢谢你写的代码,d6d0正是我想要的结果,不过我想把d6d0赋给一个变量,
    请问有什么办法?
      

  6.   

    unsigned char szString[] = "中";
    int iRes = 0;
    for (unsigned int i=0;i<strlen((char*)szString);i++)
    {
    iRes = iRes<<8 + szString[i];
    }
    ...
      

  7.   

    各位可能不太明白我的意思。
    现重新说明如下:
        CString str="中";
        int i=0xd6d0;
      其中i 是 str的ascii值(0xd6是"中"前一半的ascii值,0xd0是"中"后一半的ascii值)
      那么现在有什么办法能实现从str到i 的转换呢?
      即i=func(str),各位知不知道如何设计这个func()呢?
    非常感谢!
      

  8.   

    试试这个函数int atoi(
                     const char *string 
                   );
      

  9.   

    CString str("中国人");
    char ch[10];
    memset(byt,0,10); for(int i=0;i<str.GetLength();i++)
    ch[i]=str.GetAt(i);
      

  10.   

    上面是得到char数组。以下可以得到int型: CString str("中国人");
    int myint[10];
    memset(byt,0,10); for(int i=0;i<str.GetLength();i++)
    myint[i]=str.GetAt(i)&0xff;
      

  11.   

    其实everandforever(Forever)已经给出了方法了.int GiveMeIntForAChineseChar(unsigned char ChineseChar[])
    {
        int iRes=ChineseChar[0];
        iRes = iRes<<8 + ChineseChar[1];
        return iRes;
    }void main()
    {
       unsigned char szString[] = "中";
       cout<<GiveMeIntForAChineseChar(szString)<<endl;
    }以上程序未经测试!
      

  12.   

    试试这段:
    int *p = (int*)"中";
    int n=*p;