UTF8转GB2312(UTF8解码)

小弟C++上手没多久,代码不严谨之处敬请见谅。英语也不是很好,有的是直接使用的拼音。

string MyUTF_8toGB2312(string str)

{

    int changdu = MultiByteToWideChar(0,0,str.c_str(),-1,NULL,0);

    wchar_t* IUnicode = new wchar_t[changdu*2];

    MultiByteToWideChar(65001,0,str.c_str(),-1,IUnicode,changdu);

    changdu = WideCharToMultiByte(0,0,IUnicode,-1,NULL,0,0,0);

    char* Ichar = new char[changdu*2];

    WideCharToMultiByte(936,0,IUnicode,-1,Ichar,changdu*2,0,0);

    string temp = Ichar;

    delete []IUnicode;

    IUnicode=NULL;

    delete []Ichar;

    Ichar=NULL;

    return temp;

}

你可能感兴趣的:(utf8)