300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > c++ ANSI UNICODE UTF8互转

c++ ANSI UNICODE UTF8互转

时间:2022-05-13 11:27:23

相关推荐

c++ ANSI UNICODE UTF8互转

c++ ANSI、UNICODE、UTF8互转 staticstd::wstringMBytesToWString(constchar*lpcszString);

staticstd::stringWStringToMBytes(constwchar_t*lpwcszWString);

staticstd::wstringUTF8ToWString(constchar*lpcszString);

staticstd::stringWStringToUTF8(constwchar_t*lpwcszWString);

std::wstringKKLogObject::MBytesToWString(constchar*lpcszString)

{

intlen=strlen(lpcszString);

intunicodeLen=::MultiByteToWideChar(CP_ACP,0,lpcszString,-1,NULL,0);

wchar_t*pUnicode=newwchar_t[unicodeLen+1];

memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));

::MultiByteToWideChar(CP_ACP,0,lpcszString,-1,(LPWSTR)pUnicode,unicodeLen);

wstringwString=(wchar_t*)pUnicode;

delete[]pUnicode;

returnwString;

}

std::stringKKLogObject::WStringToMBytes(constwchar_t*lpwcszWString)

{

char*pElementText;

intiTextLen;

//widechartomultichar

iTextLen=::WideCharToMultiByte(CP_ACP,0,lpwcszWString,-1,NULL,0,NULL,NULL);

pElementText=newchar[iTextLen+1];

memset((void*)pElementText,0,(iTextLen+1)*sizeof(char));

::WideCharToMultiByte(CP_ACP,0,lpwcszWString,0,pElementText,iTextLen,NULL,NULL);

std::stringstrReturn(pElementText);

delete[]pElementText;

returnstrReturn;

}

std::wstringKKLogObject::UTF8ToWString(constchar*lpcszString)

{

intlen=strlen(lpcszString);

intunicodeLen=::MultiByteToWideChar(CP_UTF8,0,lpcszString,-1,NULL,0);

wchar_t*pUnicode;

pUnicode=newwchar_t[unicodeLen+1];

memset((void*)pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));

::MultiByteToWideChar(CP_UTF8,0,lpcszString,-1,(LPWSTR)pUnicode,unicodeLen);

wstringwstrReturn(pUnicode);

delete[]pUnicode;

returnwstrReturn;

}

std::stringKKLogObject::WStringToUTF8(constwchar_t*lpwcszWString)

{

char*pElementText;

intiTextLen=::WideCharToMultiByte(CP_UTF8,0,(LPWSTR)lpwcszWString,-1,NULL,0,NULL,NULL);

pElementText=newchar[iTextLen+1];

memset((void*)pElementText,0,(iTextLen+1)*sizeof(char));

::WideCharToMultiByte(CP_UTF8,0,(LPWSTR)lpwcszWString,-1,pElementText,iTextLen,NULL,NULL);

std::stringstrReturn(pElementText);

delete[]pElementText;

returnstrReturn;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。