std::string转为 std::wstring
std::wstring UTF8_To_UTF16(const std::string& source)
{
unsigned long len = ::MultiByteToWideChar(CP_UTF8, NULL, source.c_str(), -1, NULL, NULL); //::表示全局函数 不加:: 默认先调用类中的同名函数
if(len == 0)
return std::wstring();
wchar_t *buffer = new wchar_t[len];
::MultiByteToWideChar(CP_UTF8, NULL, source.c_str(), -1, buffer, len);
std::wstring dest(buffer);
delete[] buffer;
return dest;
}
std::wstring转为 std::string
std::string UTF16_To_UTF8(const std::wstring& source)
{
unsigned long len = ::WideCharToMultiByte(CP_UTF8, NULL, source.c_str(), -1, NULL, NULL, NULL, NULL); //::表示全局
if(0 == len)
{
return std::string();
}
char* buffer = new char[len];
::WideCharToMultiByte(CP_UTF8, NULL, source.c_str(), -1, buffer, len, NULL, NULL);
std::string dest(buffer);
delete[] buffer;
return dest;
}