I want to be able to use an ostream_iterator to stream to a binary file. But the ostream_iterator
uses a FormattedOuputFunction so it will write ASCII, not binary:<
ostreambuf_iterator is more appropriate than ostream_iterator
. It's much lighter weight and it does no formatting. It takes a template argument for the character type, so the only choice compatible with most streams is std::ostream_iterator< char >
.
Be sure to open the stream in binary mode. The standard stream buffers, by the way, are never opened in binary mode.