简体   繁体   中英

how to change cstring to unicode

i am now working in VC++ 6. and I have a cstring content. How to change to content to unicode ? for exmaple, I have a defined

CString strName;

strName Have some content in it(may some chinese character in it).

and also defined:

Unicode* chinese_character;

How to transfer the content of strName into the chinese_character ?

Note that I am working in VC++ 6.

Thanks.

After googling I find a useful function as mbstowcs() which is used to convert multibyte string to wide-character string.

Below the example for this.

{
    wchar_t buf[255];
    mbstowcs(buf,(const char*)name,name.GetLength()+1);

    BYTE bytes[255];
    size_t length = wcslen(buf);
    for (size_t i = 0; i < length; i++)
    {
      bytes[i*2] = buf[i] >> 8;
      bytes[i*2+1] = buf[i] & 0xFF;
    }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM