C++: Converting an MFC CString to a std::string
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 = new char[aLen]; WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL); return...
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 = new char[aLen];
WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
return lpa;
}
std::string WideChar2StdStr(const CString& strcs)
{
LPSTR lpa = WideChar2MBCS(strcs);
std::string stdStr(lpa);
delete [] lpa;
return stdStr;
}
I hope this will be useful.