Boost logo

Boost :

From: Ares Lagae (ares.lagae_at_[hidden])
Date: 2007-05-30 02:39:49

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) {
  else {
// 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

Boost list run by bdawes at, gregod at, cpdaniel at, john at