title: How do I read / write gzipped files in C++?
body: <p>How do I read / write gzipped files in C++?</p>
  
  <p>The <code>iostream</code> wrapper classes <a href="http://www-d0.fnal.gov/d0dist/dist/packages/lm_access/devel/lm_access/gzstream.hpp" rel="noreferrer">here</a> look good, and here is a simple usage example:</p>
  
  <pre><code>gz::igzstream in(filename);
  std::string line;
  while(std::getline(in, line)){
    std::cout &lt;&lt; line &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>But I wasn't able to actually link it (although I have a <code>/usr/lib/libz.a</code>). A simple</p>
  
  <pre><code>g++ test-gzstream.cpp -lz
  </code></pre>
  
  <p>didn't do it (<code>undefined reference to gz::gzstreambase::~gzstreambase()</code>).</p>