将unicode下的wstring转化成ansi下的string
2011-03-11 16:36
447 查看
//将unicode下的wstring转化成ansi下的string
inline std::string UnicodeToASCII(LPCTSTR lpszText)
{
int length=_tcslen(lpszText);
TCHAR* pWideCharStr=new TCHAR[length+1];
char* data=new char[2*length+2];
_tcscpy(pWideCharStr, lpszText);
WideCharToMultiByte(CP_ACP, 0, pWideCharStr, -1, data, 2*length + 2, NULL, NULL);
std::string strText = data;
delete []data;
delete []pWideCharStr;
return strText;
}
inline std::string UnicodeToASCII(LPCTSTR lpszText)
{
int length=_tcslen(lpszText);
TCHAR* pWideCharStr=new TCHAR[length+1];
char* data=new char[2*length+2];
_tcscpy(pWideCharStr, lpszText);
WideCharToMultiByte(CP_ACP, 0, pWideCharStr, -1, data, 2*length + 2, NULL, NULL);
std::string strText = data;
delete []data;
delete []pWideCharStr;
return strText;
}
相关文章推荐
- CString(ANSI/Unicode)与string/wstring的安全转换
- string 和 wstring 互相转换的方法(即 Ansi & Unicode 在标准库下的互转)
- wstring 转化为 string
- C/C++ 各种字符编码字符串的转换 可用于XML文件的字符转化读写 (收集 GBK - UTF8 - Unicode - ANSI )
- Unicode下wstring(wchar_t*)和string(char*)互相转换
- Unicode数据类型(与ANSI关系和相互转化)
- 转载 ANSI、Unicode、UTF8相互转化的函数
- CStdioFile的Writestring写入中文的总结(unicode-ucs2/utf8-无Bom/ansi-gb2312)
- 从Java String实例来理解ANSI、Unicode、BMP、UTF等编码概念
- UNICODE及ANSI切分转化问题
- 【语言国际化】字符集编码(GBK,BIG5,UNICODE)与C++的string/wstring
- ring3 char 字符数组 传入ring0后 转化为UNICODE_STRING处理
- string CString wstring 之间的转化
- C++中wstring与string相互转化
- wstring 和 string间的转化
- 字符集编码(GBK,BIG5,UNICODE等)与C++的string/wstring
- C++中wstring与string相互转化
- Unicode数据类型(与ANSI关系和相互转化)
- 字符集编码(GBK,BIG5,UNICODE等)与C++的string/wstring .
- ANSI and UnicodeCharacter and String Data Types