c++ ANSI、UNICODE、UTF8互转
来源:互联网 发布:淘宝网购物男装外套 编辑:程序博客网 时间:2024/05/01 13:23
static std::wstring MBytesToWString(const char* lpcszString);
static std::string WStringToMBytes(const wchar_t* lpwcszWString);
static std::wstring UTF8ToWString(const char* lpcszString);
static std::string WStringToUTF8(const wchar_t* lpwcszWString);
static std::string WStringToMBytes(const wchar_t* lpwcszWString);
static std::wstring UTF8ToWString(const char* lpcszString);
static std::string WStringToUTF8(const wchar_t* lpwcszWString);
std::wstring KKLogObject::MBytesToWString(const char* lpcszString)
{
int len = strlen(lpcszString);
int unicodeLen = ::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, NULL, 0);
wchar_t* pUnicode = new wchar_t[unicodeLen + 1];
memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);
wstring wString = (wchar_t*)pUnicode;
delete [] pUnicode;
return wString;
}
std::string KKLogObject::WStringToMBytes(const wchar_t* lpwcszWString)
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, -1, NULL, 0, NULL, NULL);
pElementText = new char[iTextLen + 1];
memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, 0, pElementText, iTextLen, NULL, NULL);
std::string strReturn(pElementText);
delete [] pElementText;
return strReturn;
}
std::wstring KKLogObject::UTF8ToWString(const char* lpcszString)
{
int len = strlen(lpcszString);
int unicodeLen = ::MultiByteToWideChar(CP_UTF8, 0, lpcszString, -1, NULL, 0);
wchar_t* pUnicode;
pUnicode = new wchar_t[unicodeLen + 1];
memset((void*)pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
::MultiByteToWideChar(CP_UTF8, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);
wstring wstrReturn(pUnicode);
delete [] pUnicode;
return wstrReturn;
}
std::string KKLogObject::WStringToUTF8(const wchar_t* lpwcszWString)
{
char* pElementText;
int iTextLen = ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, NULL, 0, NULL, NULL);
pElementText = new char[iTextLen + 1];
memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, pElementText, iTextLen, NULL, NULL);
std::string strReturn(pElementText);
delete [] pElementText;
return strReturn;
}
{
int len = strlen(lpcszString);
int unicodeLen = ::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, NULL, 0);
wchar_t* pUnicode = new wchar_t[unicodeLen + 1];
memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
::MultiByteToWideChar(CP_ACP, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);
wstring wString = (wchar_t*)pUnicode;
delete [] pUnicode;
return wString;
}
std::string KKLogObject::WStringToMBytes(const wchar_t* lpwcszWString)
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, -1, NULL, 0, NULL, NULL);
pElementText = new char[iTextLen + 1];
memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, 0, pElementText, iTextLen, NULL, NULL);
std::string strReturn(pElementText);
delete [] pElementText;
return strReturn;
}
std::wstring KKLogObject::UTF8ToWString(const char* lpcszString)
{
int len = strlen(lpcszString);
int unicodeLen = ::MultiByteToWideChar(CP_UTF8, 0, lpcszString, -1, NULL, 0);
wchar_t* pUnicode;
pUnicode = new wchar_t[unicodeLen + 1];
memset((void*)pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
::MultiByteToWideChar(CP_UTF8, 0, lpcszString, -1, (LPWSTR)pUnicode, unicodeLen);
wstring wstrReturn(pUnicode);
delete [] pUnicode;
return wstrReturn;
}
std::string KKLogObject::WStringToUTF8(const wchar_t* lpwcszWString)
{
char* pElementText;
int iTextLen = ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, NULL, 0, NULL, NULL);
pElementText = new char[iTextLen + 1];
memset((void*)pElementText, 0, (iTextLen + 1) * sizeof(char));
::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, -1, pElementText, iTextLen, NULL, NULL);
std::string strReturn(pElementText);
delete [] pElementText;
return strReturn;
}
0 0
- GBK UTF8 ANSI UNICODE 互转
- c++ ANSI、UNICODE、UTF8互转
- c++ ANSI、UNICODE、UTF8互转
- c++ ANSI、UNICODE、UTF8互转
- c++ ANSI、UNICODE、UTF8互转
- C++UTF8互转ANSI
- [C/C++]_[Unicode转Utf8,Ansi转Unicode,Ansi文件转Utf8文件]
- [C/C++]_[Unicode转Utf8,Ansi转Unicode,Ansi文件转Utf8文件]
- win32的ANSI、UNICODE、UTF8互转
- Unicode, ANSI, UTF8
- Unicode,Ansi和UTF8
- ANSI Unicode,UTF8 转换
- Ansi Unicode UTF8
- ANSI - Unicode - UTF8 转换
- utf8,unicode ,ansi转换
- ansi-unicode-utf8
- Ansi,UTF8,Unicode编码
- ANSI UTF8 UNICODE
- 封装ANSI,UNICODE,UTF8互相转换类
- Android Listview中使用两种布局
- AWS 经典的3层web app部署架构图
- ASP.NET的Session 详解
- Git 常用命令整理
- c++ ANSI、UNICODE、UTF8互转
- C#代码注释规范及文档生成
- fedora 下搭建DNS服务器
- C++中Ansi、Unicode、UTF8字符串之间的转换和写入文本文件
- python(py2exe)打包成exe执行文件,vista/win7下icon图标显示问题的解决方案
- 真爱来临时,你要怎么留得住
- 仿win8磁贴界面以及功能
- 小强的HTML5移动开发之路(39)——jqMobi插件json格式ActionSheet
- 肥僮谈朔