作者:朱金灿

来源:http://www.cnblogs.com/clever101

 

    CString转换为std::string,网上通行的做法是利用CString的GetBuffer函数。具体做法如下(编译环境为VS C++ 2005+sp1, Win XP+sp3,多字节字符集编译,以下同):

 
     CString strMFC= _T("Hello!");
     std::
string str2(strMFC.GetBuffer());
     strMFC.ReleaseBuffer();

      这种做法在unicode字符集下也可行。今天我探索了一种新做法,具体做法是:

CString strMFC= _T("Hello!");
TCHAR 
*psz =  (TCHAR*)(LPCTSTR)strMFC;
std::
string str3 = psz;

   

这种做法在unicode字符集下也可行。

 

相关文章:

  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2022-01-14
  • 2022-12-23
  • 2021-10-11
猜你喜欢
  • 2021-05-30
  • 2022-12-23
  • 2022-02-09
  • 2021-08-16
  • 2022-01-23
相关资源
相似解决方案