• C++ Builder 6 操作unicode


    #define _countof(array) (sizeof(array) / sizeof(array[0]))
    void __fastcall TForm1::btn1Click(TObject *Sender)
    {
        wchar_t  buf[] = L"中国人民解放军";
        WideString ws = "中国人民解放军";
        WCHAR* buf2 = ws.c_bstr();
        int a = _countof(buf);
        int b = sizeof(buf);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::btn2Click(TObject *Sender)
    {
        char* buffer = "中国人民解放军";
        int cbMultiByte = strlen(buffer) + 1;
        wchar_t wbuffer[20] = {0};
        int cchWideChar = cbMultiByte;
        MultiByteToWideChar(
            CP_ACP,
            MB_PRECOMPOSED,
            buffer,
            strlen(buffer) + 1,
            wbuffer,
            strlen(buffer) + 1
        );
    
        ShowMessage(wbuffer);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::btn3Click(TObject *Sender)
    {
        wchar_t* wbuffer = L"中国人民志愿军";
        int cchWideChar = wcslen(wbuffer) + 1;
        char buffer[20] = {0};
        int cbMultiByte = cchWideChar * sizeof(wchar_t) + 1;
    
        WideCharToMultiByte(CP_ACP,
            0,
            wbuffer,
            cchWideChar,
            buffer,
            cbMultiByte,
            NULL,
            NULL);
    
    
        DWORD err = GetLastError();
        AnsiString errMsg = SysErrorMessage(err);
    
        ShowMessage(buffer);
    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::btn4Click(TObject *Sender)
    {
        wchar_t* wbuffer = L"中国人民解放军第301医院";
        PVOID pvBuffer = wbuffer;
        int cb = (wcslen(wbuffer) + 1) * sizeof(wchar_t);
        BOOL bRet = IsTextUnicode(pvBuffer , cb , NULL);
    
        char* buffer = "中国人民解放军第309医院";
        pvBuffer = buffer;
        cb = (strlen(buffer) + 1) * sizeof(char);
        bRet = IsTextUnicode(pvBuffer , cb , NULL);
    }
  • 相关阅读:
    https://blog.csdn.net/nameofcsdn/article/details/53164652
    洛谷
    模板
    模板
    Gym 101911E "Painting the Fence"(线段树区间更新+双端队列)
    Gym 101911F “Tickets”
    图论:最小瓶颈生成树
    图论:次小生成树
    图论:费用流-SPFA+EK
    图论:Dinic算法
  • 原文地址:https://www.cnblogs.com/songr/p/15063528.html
Copyright © 2020-2023  润新知