char * 和 wchar*的转换

来源:互联网 发布:护资考试做题软件 编辑:程序博客网 时间:2024/05/22 04:36
功能:将宽字符编码字符串转换成多字节编码字符串。[1] 
头文件:#include <stdlib.h>。
函数原型:
errno_t __cdecl mbstowcs_s(size_t * _PtNumOfCharConverted, wchar_t * _DstBuf, size_t _SizeInWords, const char * _SrcBuf, size_t _MaxCount );
参数说明:[1] 
PtNumOfCharConverted:指向转换后的字符串的长度加上结束符(单位wchar_t);
_DstBuf:指向转换后的字符串首地址;
_SizeInWords:目的地址最大字空间大小(单位wchar_t);
_SrcBuf:源多字节字符串首地址;
_MaxCount:最多可存入宽字符串缓冲中的字符个数,用于裁剪转换后的宽字符串。
返回值:成功返回0, 失败则返回失败代码。



函数功能:将字符串从wchar_t*转换成char*,即从unicode字符转换成多字节字符。
函数原型:errno_t wcstombs_s( size_t *pReturnValue, char *mbstr, size_t sizeInBytes, const wchar_t *wcstr, size_t count );
头文件:
<stdlib.h>
参数说明:
pReturnValue: The number of characters converted. ----- 转换后的多字节字符串的字符数;
mbstr: The address of a buffer for the resulting converted multibyte character string. ----- char类型的字符或字符串的地址 (接收转换后的字符串的缓冲区);
sizeInBytes: The size in bytes of the mbstr buffer. ----- 用来接收转换后字符char类型缓冲区的大小(以字节记);
wcstr: Points to the wide character string to be converted. ----- wchar_t类型的字符串的地址(需要转换的字符串的缓冲区的地址);
count: The maximum number of bytes to be stored in the mbstr buffer ----- 最多可以存入mbstr的字节数。
返回值:
Zero if successful, an error code on failure.
成功返回0, 失败则返回失败代码