
Shams wrote:
Hi,
I have had a look at the example...
Questions: 1. Apart from handling endianess what is really different from iostreams opened in binary mode?
This is indeed the essence. However there are several advantages in doing that: - symmetric approach to text I/O and binary I/O - binary I/O operators for custom types - no reinterpret_casts anymore, and no sizeof problems - ...
2. Is/can the endianness BOM (byte order mark) written to the file automatically?
No, but it can be done quite easily: // write a file in the host byte order binary_ofstream ofstream("out.bin"); // ofstream is in host_byte_order uint16_t byte_order_mark = 0x1234; ofstream << byte_order_mark; // write data // read a file and detect byte order binary_ifstream ifstream("in.bin"); // ifstream is in host_byte_order uint16_t byte_order_mark; ifstream >> byte_order_mark; if (byte_order_mark != 0x1234) { if (ifstream.byte_order() == binary_ios_base::little_endian_byte_order) { ifstream.byte_order(binary_ios_base::big_endian_byte_order); } else { ifstream.byte_order(binary_ios_base::little_endian_byte_order); } } // read data There were not that much responses to my query. Should I conclude that there is no interest in a binary_iostreams library ? Best regards, -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/