Sorry I didn't reply sooner -- I've been away for the last few days. Paul Giaccone wrote:
How do you close a filtering_ostream object once you have finished writing to it?
You can use either pop() or reset().
In my program below, I would expect the file "hello.bz2" to have been written once the close() function has been called, but it is not the case. The contents are not actually written until I exit the scope in which the filtering_ostream object is defined (at which point the destructor presumably does the job).
reset() or pop() should work. This also reflects a problem with filtering_ostream which I noticed only after the feature freeze before the 1.33 release: copy calls close() on both its arguments, but close() is a no-op for filtering_streams. Instead, close() should probably call pop().
(The file "some_text.txt" contains just the text "hello world!" so I would expect it not to be written until the file is closed.)
No, the implementation is free to flush the stream at any time. Also, copy closes the stream.
I would like to be able to do this explicitly and not have to rely on the destruction of the object - could you explain how can this be done?
Another question: what should the second parameter to close() be? I've used BOOST_IOS::trunc here, but is there some other more appropriate value?
close() is meant to be called by the iostreams library; you shouldn't have to call it yourself. Thanks for using the iostreams library!
Thanks,
Paul Giaccone
-- Jonathan Turkanis www.kangaroologic.com