C 文件流,在开头附加 [英] C file streams, appending at the beginning

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

问题描述

Is there a simple way to append something at the beginning 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 it is possible to do it without my buffer.

解决方案

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

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

  1. Write the value you want inserted at the beginning of the file
  2. Read X bytes from the old file
  3. Write those X bytes to the new file
  4. Repeat 2,3 until you are done reading the old file
  5. Copy the new file to the old file.

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

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