您的位置:首页 > 其它

CString、LPSTR、std::string、LPCSTR之间的转换

2012-04-10 10:28 495 查看
LPSTR WideChar2MBCS( const CString& strCS )

{

const UINT wLen= strCS.GetLength()+
1;

UINT aLen= WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);

LPSTR lpa=
newchar[aLen];

WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);

return lpa;

}




std::string WideChar2StdStr(const
CString& strcs)






{


LPSTR l= WideChar2MBCS(strcs);


std::string stdStr(l);


delete [] l;


return stdStr;


}




LPOLESTR MBCS2WideChar( LPCSTR lpa )






{


size_t aLen= strlen(lpa)+
1;


int wLen
= MultiByteToWideChar(CP_ACP,0,lpa,aLen,NULL,0);


LPOLESTR lpw=
new WCHAR[wLen];


MultiByteToWideChar(CP_ACP,0,lpa,aLen,lpw,wLen);


return lpw;


}




CString MBCS2CString( LPCSTR lpa )






{


LPOLESTR lpw= MBCS2WideChar(lpa);


CString cstring(lpw);


delete [] lpw;


return cstring;


}




CString StdStr2CSting(const std::string&
stdStr )






{


return MBCS2CString(stdStr.c_str());


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐