MFC CFile追加字符串到问题件,追加CString到文件。追加创建Unicode格式

本文详细介绍了在CMFC代码对话框中遇到写文件乱码问题的解决方案,通过调整字符宽度设置避免了问题发生,确保了程序的正确运行。
bool CMFCcodeDlg::SaveAllScanCode(CString strSn, CString strMac, CString strBt, CString strIMEI)
{
	CString codeRecord = _T("sn_mac_bt_imei_record.txt");
	CFile mFile;
	mFile.Open(codeRecord, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
	mFile.SeekToEnd();
	CString allCode;
	allCode.Format(_T("SN:%s\tMAC:%s\tBT:%s\tIMEI:%s\r\n"), strSn, strMac, strBt, strIMEI);
	mFile.Write(allCode, allCode.GetLength()*sizeof(wchar_t));
	mFile.Flush();
	mFile.Close();

	return true;
}



出现写文件乱码,其实关键点在sizeof(wchar_t), 注意需要指定为哪种字符宽度Write( cstr, len*sizeof(wchar_t),由于字符格式原因导致无法正常写CString字符串到文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值