Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert CString to string (VC6)

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?

like image 980
Cheok Yan Cheng Avatar asked May 03 '26 16:05

Cheok Yan Cheng


1 Answers

Microsoft says that CT2CA replaces T2CA, so try the latter and see if that works.

like image 188
jdigital Avatar answered May 05 '26 05:05

jdigital



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!