C++ gzip读取文件第一次成功,但第二次调用失败

C++ gzip读取文件第一次成功,但第二次调用失败,c++,boost,io,gzip,C++,Boost,Io,Gzip,我使用boostgzip读取压缩文件。我的程序第一次调用时运行良好。但是当我第二次调用同一个函数时。它失败了。我不知道为什么它只起作用一次。谢谢 void readcheckfile(const char* _checkname,queue<Graphnode> &_q) { int _dep; int _val; Graphnode currentNode; cout<<"hererererererer\n"; fstr

我使用boostgzip读取压缩文件。我的程序第一次调用时运行良好。但是当我第二次调用同一个函数时。它失败了。我不知道为什么它只起作用一次。谢谢

void readcheckfile(const char* _checkname,queue<Graphnode> &_q)
{

    int _dep;
    int _val;
    Graphnode currentNode;
    cout<<"hererererererer\n";
    fstream _checkfile(_checkname, fstream::in | fstream::binary);
    cout<<"tthererererererer\n";
    std::stringstream _data;
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::gzip_decompressor());
    in.push(_checkfile);
    boost::iostreams::copy(in, _data);

    cout<<"aaaatthererererererer\n";
    //fstream _checkfile;
    //_checkfile.open(_checkname,fstream::in);
    _data>>_dep;
    while(_data.good())
    {
        currentNode.depth=(unsigned char)_dep;
        _data>>_val;
        currentNode.x=(unsigned char)_val;
        for(i=0;i<16;i++)
        {
            _data>>_val;
            currentNode.state[i]=(unsigned char)_val;
        }
        _q.push(currentNode);
    }
    _checkfile.close();
    //exit(0);
}

gzip解压器不读取zip存档,而是读取gzip压缩文件。至于您的问题,您应该在调试器中运行您的程序。然后,它将在故障点停止,您可以检查函数调用堆栈,以便找出程序中崩溃发生的位置。由于您不一定要刷新
cout
,因此无法真正判断程序运行了多远。使用
endl
而不是“\n”或显式刷新。还有一个调试器。您还陷入了一个常见的陷阱,即使用while(stream.good())。在尝试I/O操作之前,不会设置失败或eof的标志。因此,在您的情况下,将循环一次,然后
\u data>\u val
将失败,但您仍然使用失败的数据进行处理。不,它不会失败。只有当我尝试读取另一个文件时,它才会失败。它可以很好地读取单个文件。我的档案是20 8 12 11 9 13 15 10 14 0 5 1 6 2 7 4 8 10 12 11 11 9 1 0 6 7 5 4 8 12 11 9 13 15 10 2 1 6 5 4 8 11 9 13 10 13 10 10 10 10 14 14 2 15 1 6 7 4 8 15 11 11 12 11 9 13 14 2 15 15 10 2 6 7 14 11 11 8。。。
hererererererer
tthererererererer
aaaatthererererererer

hererererererer
tthererererererer
libc++abi.dylib: terminate called throwing an exception

=====================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   EXIT CODE: 6
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
=====================================================================================