Imagine you have a file
sink(\"example.txt\")
data.frame(a = runif(10), b = runif(10), c = runif(10))
sink()
and would want to add some hea
Either (A) Read the file in, add your header before and write back out (as Gareth suggested) ..or (B) Cache what you want write to the file somewhere and only write it all out when you've generated your header.
In C++, if you're willing to get your hands dirty, you can take the following steps.
truncate()
, ftruncate()
) to include current size plus new sizememmove()
the original file size to new position which is the new content sizeIt's probably less effort to: