MFC CString与std::string互转
清泛原创
CString cstr;
std::string stdstr;
非Unicode:
stdstr.assign( (LPSTR) (LPCTSTR) cstr); 或者 stdstr = std::string( (LPSTR) (LPCTSTR) cstr);
cstr = CString( stdstr.data() );
Unicode:
stdstr.assign( CT2A ( (LPCTSTR) cstr )); 或者 stdstr = std::string( CT2A ( (LPCTSTR) cstr ));
cstr = CString( stdstr.data() );
std::string stdstr;
非Unicode:
stdstr.assign( (LPSTR) (LPCTSTR) cstr); 或者 stdstr = std::string( (LPSTR) (LPCTSTR) cstr);
cstr = CString( stdstr.data() );
Unicode:
stdstr.assign( CT2A ( (LPCTSTR) cstr )); 或者 stdstr = std::string( CT2A ( (LPCTSTR) cstr ));
cstr = CString( stdstr.data() );