MFC CFile追加字符串到问题件,追加CString到文件。追加创建Unicode格式
2014-04-09 16:46
465 查看
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字符串到文件。
相关文章推荐
- [翻]为自定义MFC文件格式创建缩略图
- [翻]为自定义MFC文件格式创建缩略图
- 将CString字符串写入Unicode编码的txt文件
- MFC unicode转ANSI CString写入文件的操作
- mfc cfiledialog保存文件的路径的问题
- VC中使用CFile正确的追加写中文数据到文件不出现乱码-unicode字符集
- 使用Unicode字符集时用CFile把中文写入txt文件再用记事本打开出现乱码的问题
- php提取csv格式文件中的字符串出现的问题及解决办法
- MFC中Unicode与多字节编码中遇到的CString与char或char*的转化问题
- 不要再纠结在Unicode下含有CString的结构体CFile文件的输入输出了
- VS2005中CString与其他格式的转换 (UNICODE字符集带来的问题)
- MFC中Unicode与多字节编码中遇到的CString与char或char*的转化问题
- MFC,unicode下CString类型及UTF8问题
- UNICODE格式文件创建
- VC++ VS2010 MFC CString 追加append 写入文件 txt 捕捉键盘按键消息
- 字符串中不可见字符引起的创建文件失败的问题
- 移植性问题のCString类型转换,字符串操作和UNICODE、ANSI字符集
- MFC Unicode文件读取 分割字符串
- MFC Unicode CFile 不能写汉字的问题
- AB程序核心代码(MFC从文件读取一行+MFC字符串处理+C在文件末尾追加内容)