赞
踩
void CtempDlg::ConvertUTF8ToANSI(CString strUTF8,CString &strANSI)
{
int nLen = ::MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,(LPCTSTR)strUTF8,-1,NULL,0);
//返回需要的unicode长度
WCHAR * wszANSI = new WCHAR[nLen+1];
memset(wszANSI, 0, nLen * 2 + 2);
nLen = MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUTF8, -1, wszANSI, nLen); //把utf8转成unicode
nLen = WideCharToMultiByte(CP_ACP, 0, wszANSI, -1, NULL, 0, NULL, NULL); //得到要的ansi长度
char *szANSI=new char[nLen + 1];
memset(szANSI, 0, nLen + 1);
WideCharToMultiByte (CP_ACP, 0, wszANSI, -1, szANSI, nLen, NULL,NULL); //把unicode转成ansi
strANSI = szANSI;
delete wszANSI;
delete szANSI;
}
void CtempDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CStdioFile mFile;
CFileException mExcept;
mFile.Open(_T("C:\\a.txt"), CFile::modeRead);
CString string,str;
mFile.ReadString(string);
ConvertUTF8ToANSI(string,str);
mFile.Close();
CDialogEx::OnOK();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。