天天看点

c++ unicode模式下CString 到string的相互转换

void Ccstr_strDlg::OnBnClickedStr()

{

 // TODO: 在此添加控件通知处理程序代码

//CString 到string 的转换

 CString str2 = _T("一九九二年那是一个春天,有一位老人在中国的南海边划了一个圈!");

 int iSize;

     iSize = WideCharToMultiByte(CP_ACP, 0, str2.GetBuffer(), -1, NULL, 0, NULL, NULL);

     str2.ReleaseBuffer();

     char * temp=new char[iSize+1];

     WideCharToMultiByte(CP_ACP, 0, str2.GetBuffer(), -1, temp, iSize, NULL, NULL);

     str2.ReleaseBuffer();

     string m_fileName=temp;

//string 到CString的转换

 CString cstr2(m_fileName.c_str());

}