c++ 写文件到磁盘

int WriteFile(string& strPath, char* pBuf, int iLen)
{
  //数据写入文件
  if (pBuf == NULL) { return FALSE; }
  if (_access(strPath.c_str(), 0x00) == 0)
  {
    _unlink(strPath.c_str());//删除文件
  }

  ofstream file;//创建对象
  file.open(strPath, std::ios::binary | std::ios::out);//打开文件
  if (file.is_open() != TRUE) { return FALSE; }
  if (iLen > 0) { file.write(pBuf, iLen); }
  file.close();
  return TRUE;
}

posted @ 2020-10-19 22:06  龙马8586  阅读(581)  评论(0编辑  收藏  举报