c++ 讀取文件內容到臨時緩沖區


int cCommFun::ReadFile(string& strPath, char* pDest, int& iLen)
{
  if (pDest == NULL || iLen < 1) { return FALSE; }
  //文件信息寫入內存
  std::ifstream file;
  file.open(strPath.c_str(), std::ios::binary | std::ios::out);
  if (file.is_open() != TRUE) { return FALSE; }
  do
  {
    file.seekg(0, std::ios::end);// go to the end
    int iTmpLen = static_cast<int>(file.tellg());
    if (iTmpLen > 0)
    {
      if (iTmpLen > iLen) { break; }
      file.seekg(0, std::ios::beg);
      file.read(pDest, iTmpLen);
    }
    iLen = iTmpLen;
    file.close();
    return TRUE;
  } while (FALSE);
  file.close(); // close file handle
  return FALSE;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM