您的位置:首页 > 其它

MFC中如何从Unicode到多字节的转换

2016-01-30 16:29 351 查看
std::string cStringToString(const CString& src, UINT codepage = CP_UTF8)
{
std::string dst;
if (src.IsEmpty())
{
dst.clear();
return "";
}

int length = ::WideCharToMultiByte(codepage, 0, src, src.GetLength(), NULL, 0, NULL, NULL);
dst.resize(length);
::WideCharToMultiByte(codepage, 0, src, src.GetLength(), &dst[0], (int)dst.size(), NULL, NULL);

return dst;
}

CString stringToCString(const std::string& src, UINT codepage = CP_UTF8)
{
CString dst;
if (src.empty())
{
return  dst;
}
int length = ::MultiByteToWideChar(codepage, 0, src.data(), (int)src.size(), NULL, 0);
WCHAR* pBuffer = dst.GetBufferSetLength(length);
::MultiByteToWideChar(codepage, 0, src.data(), (int)src.size(), pBuffer, length);

return dst;
}


然后怎么实现CString转LPWSTR

LPWSTR = (LPWSTR)(LPCWSTR)CString
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: