title: Param syntax for substituting boost filtering_stream for std::ofstream
body: <p>Some basic questions about boost filtering_streams.  I have dozens of functions that take a parameter of std::ofstream&amp;</p>
  
  <pre><code>void foo(std::ofstream&amp; outStream)
  {
      // lots of operations, like this:
      outStream &lt;&lt; "various bits of text";
  }
  
  void StreamSomeTextToFile(char* fileName)
  {
      ofstream myFileStream(fileName, ios::out | ios::app | ios::binary);
      foo(myFileStream);
      myFileStream.close();
  }
  </code></pre>
  
  <p>Now I'd like to use the boost filtering_stream to output to a compressed ZIP file.  The commonly cited boost filtering_streams test code for packing and unpacking compiled, linked, and worked perfectly for me.  I'd like to substitute the filtering_stream:</p>
  
  <pre><code>void StreamSomeCompressedTextToFile(char* fileName)
  {
      ofstream myFileStream(destPath, std::ios_base::out | std::ios_base::app | std::ios_base::binary);
      boost::iostreams::filtering_streambuf&lt;boost::iostreams::output&gt; myCompressedFileStream;
      myCompressedFileStream.push(boost::iostreams::zlib_compressor());
      myCompressedFileStream.push(myFileStream);
  
      foo(myCompressedFileStream);    // I can't just pass myCompressedFileStream to foo(std::ofstream&amp;), right?
      myFileStream.close();
  }
  </code></pre>
  
  <p>THREE QUESTIONS:</p>
  
  <p>1) Do all my functions that previously accepted std::ofstream&amp; outStream need to now accept a parameter of type boost::iostreams::filtering_streambuf&amp; ?  Or is there a proper parameter type so those numerous ("foo") functions could work with EITHER type of stream type?</p>
  
  <p>2) In my simple test cases, I was not able to use stream operator syntax with the filtering_streambuf:</p>
  
  <pre><code>myCompressedFileStream &lt;&lt; "some text";
  </code></pre>
  
  <p>this generated the the error: no match for 'operator&lt;&lt;'.  I similarly had compile errors with write():</p>
  
  <p><code>error: 'class boost::iostreams::filtering_streambuf&lt;boost::iostreams::output, char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;, boost::iostreams::public_&gt;' has no member named 'write</code>'</p>
  
  <p>3) In the common test case example code (below), I was confused that I could not locate the file "hello.z" after it had been created.  The unpack code (also below) clearly references it -- so where can it be found?  NOTE:  the location was finally discovered: it was in the /Library/Preferences/</p>
  
  <pre><code>void pack()
  {            
      std::ofstream file("hello.z", std::ios_base::out | std::ios_base::binary);
  
      boost::iostreams::filtering_streambuf&lt;boost::iostreams::output&gt; out;
      out.push(boost::iostreams::zlib_compressor());
      out.push(file);       
      char data[5] = {'a', 'b', 'c', 'd', 'e'};    
      boost::iostreams::copy(boost::iostreams::basic_array_source&lt;char&gt;(data, sizeof(data)), out);
      file.close();
  }
  
  void unpack()
  {
      std::fstream file("hello.z", std::ios_base::in | std::ios_base::binary);
      boost::iostreams::filtering_streambuf&lt;boost::iostreams::input&gt; in;
      in.push(boost::iostreams::zlib_decompressor());
      in.push(file);
      boost::iostreams::copy(in, std::cout);
  }
  </code></pre>
  
  <p>BTW:  XCode 3.2.6, GNU 4.0, OS X 10.6.8</p>