char* 和 wchar* 转换 多字节字符串与UNICODE字符串转换
来源:互联网 发布:java 图像编程实例库 编辑:程序博客网 时间:2024/05/22 15:33
使用MultiByteToWideChar 和 WideCharToMultiByte 函数
//多字节字符转为宽字符
char st[20] = {"多字节字符串!"};
DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, st, -1, NULL, 0);
wchar_t *pwText=new wchar_t[dwNum];
if(!pwText)
{
delete []pwText;
}
MultiByteToWideChar (CP_ACP, 0, st, -1, pwText, dwNum);
delete []pwText;
//宽字符转为多字节字符的代码如下:
wchar_t wText[20] = {L"宽字符!"};
DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);
char *psText;
psText = new char[dwNum];
if(!psText)
{
delete []psText;
}
WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);
delete []psText;
使用mbstowcs_s 和 wcstombs_s 函数
// 多字节字符串转换成宽字节字符串
char *orig = "Hello, World!";
cout << orig << " (char *)" << endl;
size_t origsize = strlen(orig) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
wcscat_s(wcstring, L" (wchar_t *)");
wcout << wcstring << endl;
// 宽字节字符串转换成多字节字符串
wchar_t *orig = L"Hello, World!";
wcout << orig << L" (wchar_t *)" << endl;
size_t origsize = wcslen(orig) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, orig, _TRUNCATE);
strcat_s(nstring, " (char *)");
cout << nstring << endl;
msdn上更详细描述
http://msdn.microsoft.com/en-us/library/ms235631(VS.80).aspx
- char* 和 wchar* 转换 多字节字符串与UNICODE字符串转换
- char*和wchar*转换多字节字符串与UNICODE字符串转换
- unicode WCHAR 与多字符集char相互转换
- unicode与多字节的字符串转换
- 多字节字符串与UNICODE字符串的互相转换
- CString与char*转换(Unicode和多字节字符集)
- c++宽字符与多字节之间转换char—wchar,wchar-char
- VC++中字符串转换CString, char*, BSTR, 多字节,unicode字符集转换的问题
- C语言下Unicode字符串与多字节字符串转换方法
- wchar[] 与 char[] 转换
- 多字节与宽字符串转换
- 字符串:多字节与宽字节转换
- 多字节和Unicode转换
- 多字节字符串与宽字符串的转换
- 多字节字符串与宽字符串的转换
- 多字节字符串与宽字符串的转换
- 多字节字符串与宽字符串的转换
- 多字节字符串与宽字符串的转换
- less和more的一点点差别
- with check option
- 090903项目进展:smb资源的深层递归5,wps实现,
- Chrome的地址栏自动匹配完成(AutoComplete)
- 用MyEclipse写jsp时出现some characters acnnot be mapped using "ISO-8859-1"错误
- char* 和 wchar* 转换 多字节字符串与UNICODE字符串转换
- 第一篇
- 查找Badi和用户出口(USER EXIT)
- VS2005,Did you forget to add '#include "stdafx.h"' to your source?
- ORG.W3C.DOM操作XML
- 暑期总结
- 实战LSMW(02)
- Java的类装载器和命名空间
- 善用免费的Code Snippet Libraries加快你的开发速度