I have gz file that was created in c# with GZipStream.
I'm trying to read it in c++ line by line.
Here's the code I'm using
#include <iostream>
#include <fstream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <sstream>
int main()
{
using namespace std;
ifstream file(R"(path-to-my-file.gz)", ios_base::in | ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::zlib_decompressor());
in.push(file);
std::istream incoming(&in);
string line;
while(true)
{
getline(incoming, line);
cout << "line:"<<line << endl;
cin.get();
}
}
I have downloaded zlib from https://www.zlib.net/ and re-built boost with b2 -sZLIB_SOURCE="G:\c++source\zlib-1.2.11"
.
The problem is that the line
is always empty. What's wrong with the code above?
Problem was, I was using boost::iostreams::zlib_decompressor() instead of boost::iostreams::gzip_decompressor()