Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2005-10-07 03:40:52


Jonathan Turkanis wrote:

>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.
>
>
I didn't see this message before my earlier reply. Thank you for your
detailed explanation of what is happening - it's very useful.

Paul Giaccone


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net