我用MultiByteToWideChar怎么转都是乱码,但用CString来进行过度一下就行了靠,这是怎么回事?原理是什么?求教育

解决方案 »

  1.   

    看看CString类的构造函数CString(LPCSTR lpsz);
    // from a UNICODE string (converts to TCHAR)
    CString(LPCWSTR lpsz);
    // subset of characters from an ANSI string (converts to TCHAR)
    CString(LPCSTR lpch, int nLength);
    // subset of characters from a UNICODE string (converts to TCHAR)
    CString(LPCWSTR lpch, int nLength);
    // from unsigned characters
    CString(const unsigned char* psz);
      

  2.   

    char* WideCharToANSI( const wchar_t* szWidechar)
    {    
    int widecharLen = ::WideCharToMultiByte(CP_ACP, 0, szWidechar, -1, NULL, 0, NULL, NULL);
    char* pAnsi = new char[widecharLen+1];
    memset(pAnsi, 0x00, widecharLen+1);
    ::WideCharToMultiByte(CP_ACP, 0, szWidechar, -1, pAnsi, widecharLen, NULL, NULL); return pAnsi;
    }
    std::string WString2String(const std::wstring& wstr)
    {
    std::string strTmp(WideCharToANSI(wstr.c_str()));
    return strTmp;
    }
      

  3.   

    char* WideCharToANSI( const wchar_t* szWidechar)
    {    
    int widecharLen = ::WideCharToMultiByte(CP_ACP, 0, szWidechar, -1, NULL, 0, NULL, NULL);
    char* pAnsi = new char[widecharLen+1];
    memset(pAnsi, 0x00, widecharLen+1);
    ::WideCharToMultiByte(CP_ACP, 0, szWidechar, -1, pAnsi, widecharLen, NULL, NULL); return pAnsi;
    }
    std::string WString2String(const std::wstring& wstr)
    {
    std::string strTmp(WideCharToANSI(wstr.c_str()));
    return strTmp;
    }