Saturday, March 27, 2010

Conversion between CString & std::string

[How to convert CString to std::string]

In Visual Studio 6.0
One used to:

string mystring;
CString myCString("this is a CString");
mystring=(LPCTSTR)myCString;

However, it is not available anymore in Visual Studio 2005.
One should use "CT2CA" do like this:

string mystring;
CString myCString("this is a CString");
CT2CA myCT2CA(myCString);
mystring=myCString;