ostream_iterator for Binary Output

后端 未结 3 810
时光取名叫无心
时光取名叫无心 2021-01-22 06:47

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:<

3条回答
  •  不要未来只要你来
    2021-01-22 07:36

    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.

提交回复
热议问题