包含中文的QString 转 char*

void QString2ANSI(QString text, char **pOut)
{
    std::wstring wIn = text.toStdWString();
    char *pcstr = (char *)malloc(sizeof(char)*(2 * wcslen(wIn.c_str())+1));
    memset(pcstr , 0 , 2 * wcslen(wIn.c_str())+1 );
    int len = WideCharToMultiByte(CP_ACP, NULL, wIn.c_str(), wcslen(wIn.c_str()), NULL, 0, NULL, NULL);
    *pOut = (char *)oef_crt_malloc(len + 1);
    WideCharToMultiByte(CP_ACP, NULL, wIn.c_str(), wcslen(wIn.c_str()), *pOut, len, NULL, NULL);
    (*pOut)[len] = '\0';
}

你可能感兴趣的:(C++)