C++ 中字符串操纵--宽窄字符转换的实例详解
发布时间:2020-12-28 21:49:41 所属栏目:创业 来源:网络整理
导读:C++ 中字符串操纵--宽窄字符转换的实例详解 MultiByteToWideChar int MultiByteToWideChar( _In_ UINT CodePage,_In_ DWORD dwFlags,_In_ LPCSTR lpMultiByteStr,_In_ int cbMultiByte,_Out_opt_ LPWSTR lpWideCharStr,_In_ int cchWideChar ); 参数描写: C
|
C++ 中字符串操纵--宽窄字符转换的实例详解 MultiByteToWideChar
int MultiByteToWideChar(
_In_ UINT CodePage,_In_ DWORD dwFlags,_In_ LPCSTR lpMultiByteStr,_In_ int cbMultiByte,_Out_opt_ LPWSTR lpWideCharStr,_In_ int cchWideChar
);
参数描写:
CodePage:常用CP_ACP、CP_UTF8
dwFlags:0
lpMultiByteStr [in]:
指向待转换字符串。
cbMultiByte [in]:
lpMultiByteStr "以字节规格计较"的巨细。
配置 0,函数失败;
配置 -1,函数处理赏罚整个字符串,包罗 字符串,导致宽字符串也会带有 字符,返回的长度也包括 的长度;
配置 >0,按照是否包括 ,返回的功效也会响应调解。
lpWideCharStr [out,optional]:
指向吸取宽字符串的缓冲区。
cchWideChar [in]:
lpWideCharStr 指向的缓冲区"以字符规格计较"的巨细。
配置 0,使 lpWideCharStr 无效,并使得函数返回所需"以字符规格计较"的巨细。
Code:
int requiredBufSize = MultiByteToWideChar(CP_ACP,src,-1,NULL,0);
if (requiredBufSize > 0)
{
WCHAR *pBuffer = new WCHAR[requiredBufSize];
MultiByteToWideChar(CP_ACP,pBuffer,requiredBufSize);
}
WideCharToMultiByte int WideCharToMultiByte( _In_ UINT CodePage,_In_ DWORD dwFlags,_In_ LPCWSTR lpWideCharStr,_In_ int cchWideChar,_Out_opt_ LPSTR lpMultiByteStr,_In_ int cbMultiByte,_In_opt_ LPCSTR lpDefaultChar,_Out_opt_ LPBOOL lpUsedDefaultChar ); 参数描写: lpDefaultChar [in,optional]:NULL lpUsedDefaultChar [out,optional]:NULL 其余参数参考 MultiByteToWideChar Code:
int requiredBufSize = WideCharToMultiByte(CP_ACP,NULL);
if (requiredBufSize > 0)
{
char *pBuffer = new char[requiredBufSize];
WideCharToMultiByte(CP_ACP,requiredBufSize,NULL);
}
若有疑问请留言可能到本站社区交换接头,感激阅读,但愿能辅佐到各人,感谢各人对本站的支持! (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

