
I'm still pretty inexperienced with the iostreams library, so this may be a simple question. I'm trying to use GIL to write a PNG to a memory stream instead of a file stream. The write_view() function in the new version of GIL's io extension expects an ostream opened in binary mode as it's first parameter, such as: using namespace std; using namespace boost::gil; ofstream outputStream( "foo.png", ios::out | ios::binary ); write_view( outputStream, const_view(image), png_tag() ); I'm attempting to write to memory instead of a file, by doing this: using namespace boost::gil; using namespace boost::iostreams; typedef stream< back_insert_device< std::vector<char> > > BufferStream; std::vector<char> buffer; BufferStream bufferStream( buffer ); write_view( bufferStream, const_view(image), png_tag() ); The data that ends up in buffer is identical to the data that ends up in foo.png from the first example if I don't open outputStream in binary mode. So how can I make a binary memory stream with the iostreams library? Do I need to write my own filter?