如何详细解析宽字符与普通字符转换的实例?
- 内容介绍
- 文章标签
- 相关推荐
本文共计424个文字,预计阅读时间需要2分钟。
C++ 宽字符与普通字符的转换实例详解:将字符串转换成宽字符串,示例代码:wstring string2Wstring(string sToMatch) {
C++宽字符与普通字符的转换实例详解
把字符串转换成宽字符串,
实例代码:
wstring string2Wstring(string sToMatch) { #ifdef _A_WIN int iWLen = MultiByteToWideChar( CP_ACP, 0, sToMatch.c_str(), sToMatch.size(), 0, 0 ); // 计算转换后宽字符串的长度。(不包含字符串结束符) wchar_t *lpwsz = new wchar_t [iWLen + 1]; MultiByteToWideChar( CP_ACP, 0, sToMatch.c_str(), sToMatch.size(), lpwsz, iWLen ); // 正式转换。 lpwsz[iWLen] = L'/0'; wstring wsToMatch(lpwsz); delete []lpwsz; #elif _A_LINUX setlocale( LC_CTYPE, "" ); // 很重要,没有这一句,转换会失败。
本文共计424个文字,预计阅读时间需要2分钟。
C++ 宽字符与普通字符的转换实例详解:将字符串转换成宽字符串,示例代码:wstring string2Wstring(string sToMatch) {
C++宽字符与普通字符的转换实例详解
把字符串转换成宽字符串,
实例代码:
wstring string2Wstring(string sToMatch) { #ifdef _A_WIN int iWLen = MultiByteToWideChar( CP_ACP, 0, sToMatch.c_str(), sToMatch.size(), 0, 0 ); // 计算转换后宽字符串的长度。(不包含字符串结束符) wchar_t *lpwsz = new wchar_t [iWLen + 1]; MultiByteToWideChar( CP_ACP, 0, sToMatch.c_str(), sToMatch.size(), lpwsz, iWLen ); // 正式转换。 lpwsz[iWLen] = L'/0'; wstring wsToMatch(lpwsz); delete []lpwsz; #elif _A_LINUX setlocale( LC_CTYPE, "" ); // 很重要,没有这一句,转换会失败。

