Convert CString to string (VC6)
Posted
by Yan Cheng CHEOK
on Stack Overflow
See other posts from Stack Overflow
or by Yan Cheng CHEOK
Published on 2010-06-02T01:13:15Z
Indexed on
2010/06/02
1:23 UTC
Read the original article
Hit count: 290
c++
|visual-c++
I want to convert CString to string. (Yup. I know what am I doing. I know the returned string will be incorrect, if CString value range is outside ANSI, but That's Is OK!)
The following code will work under VC2008.
std::string Utils::CString2String(const CString& cString)
{
// Convert a TCHAR string to a LPCSTR
CT2CA pszConvertedAnsiString (cString);
// construct a std::string using the LPCSTR input
std::string strStd (pszConvertedAnsiString);
return strStd;
}
But VC6 doesn't have CT2CA macro. How I can make the code to work as well in both VC6 and VC2008?
© Stack Overflow or respective owner