C++: Converting an MFC CString to a std::string
As you use CString, you have access to the CW2A ATL macro, assuming that you work with _UNICODE defined, here it is:CString theCStr;...std::string STDStr( CW2A( theCStr.GetString() ) );which will convert to "system encoding on the user's machine" (thanks Nemanja[^] comment !), if you...
As you use
CString
, you have access to the CW2A ATL macro, assuming that you work with _UNICODE defined, here it is:
CString theCStr; ... std::string STDStr( CW2A( theCStr.GetString() ) );which will convert to "system encoding on the user's machine" (thanks Nemanja[^] comment !), if you want to specify the code page, UTF-8 encoded for example as the original, here it is:
CString theCStr; ... std::string STDStr( CW2A( theCStr.GetString(), CP_UTF8 ) );:)