C++实现UTF-8编码和Unicode编码互转
来源:互联网 发布:金融证券软件 编辑:程序博客网 时间:2024/05/18 03:16
转自:http://www.itstrike.cn/Question/5e977ab5-e035-4595-a35b-91aae63fa394.html
1.UTF-8转Unicode
wstring UTF8ToUnicode( const string& str ){ int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, NULL, 0 ); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen ); wstring rt; rt = ( wchar_t* )pUnicode; delete pUnicode; return rt; }
2.Unicode转UTF-8
string UnicodeToUTF8( const wstring& str ){ char* pElementText; int iTextLen; // wide char to multi char iTextLen = WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL ); pElementText = new char[iTextLen + 1]; memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) ); ::WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL ); string strText; strText = pElementText; delete[] pElementText; return strText;}
0 0
- C++实现UTF-8编码和Unicode编码互转
- UTF-8转Unicode 编码 C语言
- unicode和UTF-8编码
- UTF-8编码和UNICODE
- Unicode和UTF-8编码
- ASCII编码和UNICODE、utf-8编码
- unicode编码和utf-8编码详解
- 关于Unicode编码和UTF-8编码
- Unicode编码:UTF-8和UTF-16
- unicode 转 utf-8编码
- C语言 获取汉字unicode和utf-8编码
- PHP实现Unicode和Utf-8编码相互转换
- 字符编码:ASCII,Unicode和UTF-8
- 字符编码:ASCII,Unicode和UTF-8
- 【编】编码知识:Unicode和UTF-8
- 字符编码:ASCII,Unicode和UTF-8
- 字符编码:ASCII,Unicode和UTF-8
- 字符编码:ASCII,Unicode和UTF-8
- Lock内部实现
- win7下 安卓环境搭建
- static 和 const的区别与联系
- HEVC牛人博客
- 111
- C++实现UTF-8编码和Unicode编码互转
- 使用cocoapods的项目如何使用单元测试?
- DUKPT算法简析-3
- 安卓cocos2d游戏开发1.0
- 矩阵乘法学习笔记
- Merge Intervals
- hue 的安装
- SDK Manager 闪退的解决方案
- (C#) 内置 委托(1)