C文件流,在beggining追加 [英] C file streams , appending at the beggining

查看:170
本文介绍了C文件流,在beggining追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法在使用文件流的文本文件的一开始就追加的东西吗?因为我能想到的唯一的办法就是将文件加载到缓冲区中,写文本到追加,然后写缓冲区。我想知道,如果可能做到这一点没有我的缓冲区。

Is there a simple way to append something at the beggining of a text file using file streams ? Because the only way i can think of is to load a file into a buffer , write text-to-append and then write the buffer. I want to know if its possible to do it without my buffer.

推荐答案

没有,它是不可能的。你不得不重写开头插入文本文件。

No, its not possible. You'd have to rewrite the file to insert text at the beginning.

编辑:您能避免读取整个文件到内存中,如果你使用的临时文件,即:

You could avoid reading the whole file into memory if you used a temporary file ie:


  1. 写你要插入到文件的开头
  2. 价值
  3. 从旧文件读取X字节

  4. 写那些X字节到新文件

  5. 2,3重复,直到你读完旧文件

  6. 复制新文件到旧的文件。

这篇关于C文件流,在beggining追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆