I am trying to read zcat output through popen in c++. It works perfectly Ok, if I don't use C++ string. As soon as I declare "string a;", I get segmentation fault at getline. Segmentation fault goes away if I change getline with fgets. I need both. I am using g++4.0.
Second problem is that I get the last line twice when I make it work with cstring.
//using namespace std;
const string CMD = "gunzip -c ";
const int MAX_BUFFER = 2048;
string filename, cmd;
size_t len = 2048;
filename = "/path/file.log.gz";
cmd = CMD + filename;
fp = popen( cmd.c_str() , "r");
if(::getline(&line, &len, fp))
//if(fgets(line, MAX_BUFFER, fp) != NULL)