首页 > 其他 > 详细

ifstream 和 ofstream 用法。

时间:2015-12-02 09:16:02      阅读:313      评论:0      收藏:0      [点我收藏+]
outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了





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; }

 

ifstream 和 ofstream 用法。

原文:http://www.cnblogs.com/XiHua/p/5011938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!