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 Generate and use the ssh key on Gerrit, github.io, gitlab, and bitbucket.

 Details can be found here -