zoukankan      html  css  js  c++  java
  • ifstream 和 ofstream 用法。

    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; }
  • 相关阅读:
    从MySQL全备文件中恢复单个库或者单个表
    594. Longest Harmonious Subsequence
    205. Isomorphic Strings
    274. H-Index
    219. Contains Duplicate II
    217. Contains Duplicate
    操作系统-多用户如何理解(Linux)
    Java-面向对象
    C++-有感
    C++-Typedef结构体遇上指针
  • 原文地址:https://www.cnblogs.com/XiHua/p/5011938.html
Copyright © 2011-2022 走看看