[iostreams] stream and ios_base::binary
Is there a way to construct a boost::iostreams::stream with the ios_base::binary flag? I'd be really happier without the line-ending treatment... -- Pedro Lamarão
Pedro Lamarão wrote:
Is there a way to construct a boost::iostreams::stream with the ios_base::binary flag?
How line endings are treated is completely dependent upon the Device you pass to boost::iostreams::stream. Of the Devices provided by the iostreams library, only the file wrappers (www.boost.org/libs/iostreams/doc/index.html?path=4.2.2.10) provide line-ending conversions by default. In general, if you want to enable line-ending conversions for a user-defined device, you have to compose it with a newline filter (www.boost.org/libs/iostreams/doc/index.html?path=4.2.10.1).
I'd be really happier without the line-ending treatment...
-- Jonathan Turkanis www.kangaroologic.com
Pedro, I have been using iostream's file_sink and file_source with the binary flag and everything is working fine. One hint, if you're opening file with that flag I would use the read() or write() of the std:: fstream interace, only. I have had bad experience with all those operator >>() . Greets, Christian
Christian Henning wrote:
Pedro, I have been using iostream's file_sink and file_source with the binary flag and everything is working fine.
Glad to hear it.
One hint, if you're opening file with that flag I would use the read() or write() of the std:: fstream interace, only. I have had bad experience with all those operator >>() .
The formatted i/o operators such as << and >> treat whitespace specially and so aren't well suited for binary i/o.
Greets, Christian
-- Jonathan Turkanis www.kangaroologic.com
Christian Henning wrote:
Pedro, I have been using iostream's file_sink and file_source with the binary flag and everything is working fine.
One more thing: if you want to do binary i/o portably with the file wrappers, you need to manually imbue the classic locale, in case the global local is set to something more exotic. If you want to avoid this, you can use file_descriptor and friends (www.boost.org/libs/iostreams/doc/index.html?path=4.2.5.2).
Greets, Christian
-- Jonathan Turkanis www.kangaroologic.com
participants (3)
-
Christian Henning
-
Jonathan Turkanis
-
Pedro Lamarão