MFC数据类型转换

来源:互联网 发布:电脑实时监控软件 编辑:程序博客网 时间:2024/05/20 04:11
CString->int 
CString str("1234"); 
int i= _ttoi(str);

CString->const char*
const char* CXmlCtrl::cstoc(CString s)
{
int len = WideCharToMultiByte(CP_UTF8, 0, s, s.GetLength(),NULL, 0, NULL, NULL);
char * c = new char [len + 1];
len = WideCharToMultiByte(CP_UTF8, 0, s, s.GetLength(), c, len+ 1, NULL, NULL);
c[len] = 0;
return (const char*)c;
}

WCHAR*->char*
void CXmlCtrl::w2c(char *pcstr,const wchar_t *pwstr, size_tlen)
{
int nlength=wcslen(pwstr);
//获取转换后的长度
int nbytes = WideCharToMultiByte(0, 0, pwstr, nlength, NULL,0, NULL, NULL );
if(nbytes>len)   nbytes=len;
// 通过以上得到的结果,转换unicode 字符为ascii 字符
WideCharToMultiByte(0, 0, pwstr, nlength, pcstr, nbytes, NULL,NULL );
}
0 0
原创粉丝点击