[LC++]Copying binary files with operator<< and rdbuf()
Jack Lloyd
lloyd at randombit.net
Sat Nov 22 10:18:01 UTC 2003
On Fri, 21 Nov 2003, Brian Nelson wrote:
> So, uhhh, is it OK to use operator<<(basic_streambuf...) ? To me the
> above says both yes and no.
I agree. :/ Though (I think) when it refers to <</>>, it means for
formatting ones (<<(double) and so on), at least more so than the streambuf
stuff. Personally, I see no reason why what you're doing shouldn't work,
but I don't exactly know the iostreams library inside and out, either.
> Stroustrup says:
>
> It is possible to use << to write a streambuf directly into an
> ostream. This is primarily handy for implementers of I/O mechanisms.
>
> Isn't that exactly what I'm trying to do?
Out of context (the quote, I mean), I can't tell (I am 3000 miles away from
my copy). "I/O mechanims" can mean quite a number of things.
> If I can't safely use fstreams to copy a binary file, what is a better
> way?
You can use the low-level write/read calls for this; read 4K (or whatever),
from one, write to the other. This is, of course, very low-level, ugly,
inefficent, and so forth. But it does work.
-Jack
More information about the tuxCPProgramming
mailing list