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 buff...

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.

C 文件流的定位

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

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

阅读全文

相关推荐

最新文章