多字节与宽字节相互转换的方法
来源:互联网 发布:懒人源码 编辑:程序博客网 时间:2024/06/11 01:56
也就是WideCharToMultiByte和MultiByteToWideChar函数的使用方法。
多字节向宽字节转换:
wstring converToWideChar( 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;
}
宽字节向多字节转换:
string converToMultiChar( const wstring& str )
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/primer_programer/archive/2007/12/26/1968141.aspx
- 多字节与宽字节相互转换的方法
- 多字节与宽字节相互转换的方法
- 多字节与宽字节字符串的相互转换
- 多字节与宽字节字符串 的相互转换
- mfc宽字节widechar与多字节multiChar相互转换
- mfc宽字节widechar与多字节multiChar相互转换
- C++多字节字符与宽字节字符相互转换
- VC 宽字节和多字节的相互转换
- VC 宽字节和多字节的相互转换
- VC下多字节与宽字节之间的相互转换
- 多字节字符串与宽字节字符串的相互转化
- 多字节与宽字符相互转换
- 多字节和宽字节互相转换的方便方法
- Visual Studio中宽字节和多字节相互转换
- Windows 的多字节与宽字节的转换
- C++多字节与宽字节 转换
- 宽字节与多字节转换函数
- 字符串:多字节与宽字节转换
- SetDIBitsToDevice函数的理解
- oracle实现分页
- IPicture、BITMAP、HBITMAP和CBitmap的关系
- MFC让文档/视图结构程序支持滚动条
- VC中CRectTracker在CScrollView中的问题解决办法
- 多字节与宽字节相互转换的方法
- 如何解决绘图过程中的闪烁
- 如何解决绘图过程中的闪烁
- 理解shannon信息论中的自信息量
- 如何解决绘图过程中的闪烁
- ArcGIS在线应用介绍(6)北温哥华区市政项目查询系统
- 如何使Eclipse显示出文本行号
- 2011/04/08 服务器端开发
- 学计算机好无聊