宽字节wchar_t* 转换 单字节char*
2012-08-21 15:26
239 查看
// 将 宽字节wchar_t* 转换 单字节char*
inline std::string UnicodeToAnsi( const wchar_t* szStr )
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
return NULL;
}
//char* pResult = new char[nLen];
std::string res;
res.resize(nLen);
WideCharToMultiByte( CP_ACP, 0, szStr, -1, (char*)res.c_str(), nLen, NULL, NULL );
return res;
}
inline std::string UnicodeToAnsi( const wchar_t* szStr )
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
return NULL;
}
//char* pResult = new char[nLen];
std::string res;
res.resize(nLen);
WideCharToMultiByte( CP_ACP, 0, szStr, -1, (char*)res.c_str(), nLen, NULL, NULL );
return res;
}
相关文章推荐
- C++多字节与宽字节间的转换(wchar_t与char转换)
- 各种类型字符之间的转换(单字节char*和宽字节wchar_t*,TCHAR和string的转换)
- C++多字节与宽字节间的转换(wchar_t与char转换)
- c总结11 -- 多字节与宽字节间的转换(wchar_t与char转换)
- 字节码问题--wchar和char的区别以及wchar和char之间的相互转换字符编码转换等方法及函数介绍
- C++多字节与宽字节间的转换(wchar_t与char转换)
- C++多字节与宽字节间的转换(wchar_t与char转换)
- 字节码问题--wchar和char的区别以及wchar和char之间的相互转换字符编码转换等方法及函数介绍
- c++宽字符与多字节之间转换char—wchar,wchar-char
- [转载]字节码问题--wchar和char的区别以及wchar和char之间的相互转换字符编码转换等方法及函数介绍
- wchar_t和char之间的转换
- 关于MultiByteToWideChar与WideCharToMultiByte代码测试(宽字符与多字节字符的转换)以及字符串的转换代码测试
- 将char转换为wchar_t
- C++中char*\wchar_t*\string\wstring之间的相互转换
- VC宽字节与多字节转换,应之一 CString宽字节转char
- 宽字节与char*之间转换
- c++中char*\wchar_t*\string\wstring之间的相互转换
- wchar_t与char类型的转换
- char[]转换成wchar_t的转换方法(GNU Libc规定wchar_t为32位)
- wchar_t*,wchar_t,wchat_t数组,char,char*,char数组,std::string,std::wstring,CString....转换