title: How to use boost::iostreams::filtering_wistream to read a gz file in UTF-16LE?
body: <p>I have a file <code>test.txt</code> written in UTF16-LE, whose contents are as follows:</p>
  
  <pre><code>ab
  c
  </code></pre>
  
  <p>Now I compressed it with <code>gz</code> and got a new file <code>test.txt.gz</code>, I want to read this gz file and get the original contents(which is <code>ab</code> and <code>c</code>).</p>
  
  <p>I decided to use <code>boost::iostreams::filtering_wistream</code> to do it. Here is what I've tried.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/iostreams/device/file.hpp&gt;
  #include &lt;boost/iostreams/filtering_stream.hpp&gt;
  #include &lt;boost/iostreams/filter/gzip.hpp&gt;
  #include &lt;codecvt&gt;
  
  int main() {
      std::wifstream wInputFileStream("/tmp/test.txt.gz");
      wInputFileStream.imbue(std::locale(wInputFileStream.getloc(), new std::codecvt_utf16&lt;
              wchar_t, 0x10ffff, static_cast&lt;std::codecvt_mode&gt;(std::little_endian | std::consume_header)&gt;));
  
      boost::iostreams::filtering_wistream wFilteringInputStream;
      wFilteringInputStream.push(boost::iostreams::gzip_decompressor());
      wFilteringInputStream.push(wInputFileStream);
  
      wchar_t c;
      wInputFileStream.get(c); // trying to get the first character in the file, as a test
      std::cout &lt;&lt; c &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>But it doesn't work, I got a lot of errors, here are some of them.</p>
  
  <pre><code>In file included from /usr/include/boost/iostreams/filtering_streambuf.hpp:17,
                   from /usr/include/boost/iostreams/filtering_stream.hpp:22,
                   from /home/searene/CLionProjects/cmake-test/hello.cpp:6:
  /usr/include/boost/iostreams/chain.hpp: In instantiation of ‘void boost::iostreams::detail::chain_base&lt;Self, Ch, Tr, Alloc, Mode&gt;::push_impl(const T&amp;, std::streamsize, std::streamsize) [with T = boost::iostreams::basic_gzip_decompressor&lt;&gt;; Self = boost::iostreams::chain&lt;boost::iostreams::input, wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;; Ch = wchar_t; Tr = std::char_traits&lt;wchar_t&gt;; Alloc = std::allocator&lt;wchar_t&gt;; Mode = boost::iostreams::input; std::streamsize = long int]’:
  /usr/include/boost/iostreams/chain.hpp:205:5:   required from ‘void boost::iostreams::detail::chain_base&lt;Self, Ch, Tr, Alloc, Mode&gt;::push(const T&amp;, std::streamsize, std::streamsize, typename boost::disable_if&lt;boost::iostreams::is_std_io&lt;T&gt; &gt;::type*) [with T = boost::iostreams::basic_gzip_decompressor&lt;&gt;; Self = boost::iostreams::chain&lt;boost::iostreams::input, wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;; Ch = wchar_t; Tr = std::char_traits&lt;wchar_t&gt;; Alloc = std::allocator&lt;wchar_t&gt;; Mode = boost::iostreams::input; std::streamsize = long int; typename boost::disable_if&lt;boost::iostreams::is_std_io&lt;T&gt; &gt;::type = void]’
  /usr/include/boost/iostreams/chain.hpp:496:7:   required from ‘void boost::iostreams::detail::chain_client&lt;Chain&gt;::push_impl(const T&amp;, std::streamsize, std::streamsize) [with T = boost::iostreams::basic_gzip_decompressor&lt;&gt;; Chain = boost::iostreams::chain&lt;boost::iostreams::input, wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;; std::streamsize = long int]’
  /usr/include/boost/iostreams/chain.hpp:484:5:   required from ‘void boost::iostreams::detail::chain_client&lt;Chain&gt;::push(const T&amp;, std::streamsize, std::streamsize, typename boost::disable_if&lt;boost::iostreams::is_std_io&lt;T&gt; &gt;::type*) [with T = boost::iostreams::basic_gzip_decompressor&lt;&gt;; Chain = boost::iostreams::chain&lt;boost::iostreams::input, wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;; std::streamsize = long int; typename boost::disable_if&lt;boost::iostreams::is_std_io&lt;T&gt; &gt;::type = void]’
  /home/searene/CLionProjects/cmake-test/hello.cpp:16:69:   required from here
  /usr/include/boost/iostreams/chain.hpp:258:9: error: no matching function for call to ‘std::__cxx11::list&lt;boost::iostreams::detail::linked_streambuf&lt;wchar_t, std::char_traits&lt;wchar_t&gt; &gt;*, std::allocator&lt;boost::iostreams::detail::linked_streambuf&lt;wchar_t, std::char_traits&lt;wchar_t&gt; &gt;*&gt; &gt;::push_back(std::unique_ptr&lt;boost::iostreams::stream_buffer&lt;boost::iostreams::basic_gzip_decompressor&lt;&gt;, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt;, boost::iostreams::input&gt;, std::default_delete&lt;boost::iostreams::stream_buffer&lt;boost::iostreams::basic_gzip_decompressor&lt;&gt;, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt;, boost::iostreams::input&gt; &gt; &gt;::pointer)’
           list().push_back(buf.get());
           ^~~~
  </code></pre>
  
  <p>What have I done wrong? How to make it work?</p>
  
  <hr>
  
  <p>About the duplicate:</p>
  
  <p>I've already checked <a href="https://stackoverflow.com/questions/25934157/using-gzip-compressor-with-boostiostreamsfiltering-wostream-compiler-error">this question</a>, it's different from mine. That question is about how to write, and mine is about how to read. Also, the most important thing is, I cannot hold all the data in a variable when the file I want to read is very large. But for that question, it's not a problem, since it already has a <code>wstring</code> that holds all the data. So the answer to that question isn't helpful to me, either.</p>