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

原文地址:https://www.cnblogs.com/longma8586/p/13849249.html