Saturday, August 17, 2013

How to convert between 'CString' and 'std::string' ?

ISSUE:

When you are developing MFC project in most cases it becomes necessary to convert between 'CString' and 'std::string' .

SOLUTION:

'CString' to 'std::string':


 CString sTest ("Matrix");

  // Convert a TCHAR string to a LPCSTR
 CT2CA CStringToAscii(sTest);

  // construct a std::string using the LPCSTR input
 std::string sResultedString (CStringToAscii);


'std::string' to 'CString':

std::string sTest("Matrix");
CString ResultedCString(sTest.c_str());
 

No comments:

Post a Comment

How to enable hotspot in TPG iPhone

 By default, the hotspot does not work on the phone. It will ask you to contact the provider. This video will help you bypass the network ...