关于#c++#的问题:请问怎么UTF-8字符集转为ANSI字符集

遇到字符集转换的问题,一直提示报错,不知道怎么把UTF-8字符集转为ANSI字符集,用代码来转中文字符

有写过 可参考


CString MachinePara::Utf82Ansi(CString& srcCode)
{    
    int srcCodeLen=0;
    //计算接收到待转换字符串的缓冲区所需宽字符数
    srcCodeLen=MultiByteToWideChar(CP_UTF8,NULL,srcCode,srcCode.GetLength(),NULL,0);
    wchar_t* result_t=new wchar_t[srcCodeLen+1];
    //向result_t缓冲区写入宽字符
    MultiByteToWideChar(CP_UTF8,NULL,srcCode,srcCode.GetLength(),result_t,srcCodeLen);
    result_t[srcCodeLen]='\0';
    //计算接收到待转换字符串的缓冲区所需字节数
    srcCodeLen=WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),NULL,0,NULL,NULL);
    char* result=new char[srcCodeLen+1];
    //向result缓冲区写入字符
    WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),result,srcCodeLen,NULL,NULL);
    result[srcCodeLen]='\0';
    CString srcAnsiCode;
    srcAnsiCode=result;
    delete []result_t;
    delete []result;
    return srcAnsiCode;
}