ifstream 和 ofstream 用法。
2015-12-02 09:06
218 查看
[b]outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了[/b] bool CTestEn_DecryptDLLDlg::WriteDataFile(CString strFileName, char *pContent, int nLen) { ofstream outfile(strFileName, ios::out | ios::binary | ios::ate | ios::app); if (!outfile) { AfxMessageBox(_T("Unable to open outfile")); return false; } //for (int i = 0; i < nLen; ++i) //{ // outfile << pContent[i]; //} //outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了 outfile.write(pContent, nLen); outfile.close(); } bool CTestEn_DecryptDLLDlg::ReadDataFile(CString strFileName, char *pContent, int &nLen) { ifstream inFile(strFileName, ios::in | ios::binary); if (!inFile) { AfxMessageBox(_T("Unable to open inFile")); return false; } inFile.seekg(0, ios::beg); //int i = 0; //while (!inFile.eof()) //{ // inFile.get(pContent[i]); // ++i; //} //nLen = i - 1; memset(pContent, 0, nLen);//初始化FileContent inFile.read(pContent, nLen);//读取数据 inFile.close();//关闭ifstream对像 return true; }
相关文章推荐
- 防止表单重复提交的校验
- ubuntu下smartgit给已有仓库添加远程仓库
- 《leetCode》:Combinations
- ASP.NET微信开发(接口指南)
- LeetCode----Isomorphic Strings
- 关于Thread(lambda,全局捕获异常AppDomain.CurrentDomain.UnhandledException)
- 电子水墨屏-原理
- 12月上旬的一些记录
- 书签打印Word文档,包含单选复选框之类
- 微软发布新的3D扫描应用程序,让3D打印更容易-趋梦工厂
- Android下GPRS定位
- java swing MenuItem乱码处理
- webDriver 使用笔记(一)
- python自动化测试(2)-自动化基本技术原理
- Android 代码中杀死进程
- Java算法---求面积
- Swift UIButton 和 UILabel 的详细解释和创建使用
- SQL笔记(9)_第九章 汇总查询得到的数据
- android DatePicker使用
- (MongoDB系列之合并MongoDB子文档