Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在Poco::DeflatingOutputStream中查找索引_C++_C++11_Gzip_Poco_Poco Libraries - Fatal编程技术网

C++ 如何在Poco::DeflatingOutputStream中查找索引

C++ 如何在Poco::DeflatingOutputStream中查找索引,c++,c++11,gzip,poco,poco-libraries,C++,C++11,Gzip,Poco,Poco Libraries,您好,我是Poco的新手,请您帮助我找到一种方法,在写入压缩流期间获取索引/位置,以便我可以截断无效数据并确保我的文件只包含有效数据 #include <stdexcept> #include <stdarg.h> #include <map> #include <iostream> #include <cstring> #include <fstream> #incl

您好,我是Poco的新手,请您帮助我找到一种方法,在写入压缩流期间获取索引/位置,以便我可以截断无效数据并确保我的文件只包含有效数据

    #include <stdexcept>
    #include <stdarg.h>
    #include <map>
    #include <iostream>
    #include <cstring>
    #include <fstream>
    #include <Poco/DeflatingStream.h>
    #include <stdio.h>
    #include <limits>
    #include <stdio.h>
    #include <unistd.h>
    using namespace std;

        std::ofstream* ostr;
        Poco::DeflatingOutputStream* ofstr;
        string fileName="/home/lamb/Cpp/simple.gzip";
        bool written = false;
        // int lastsucessfulwrite;

    compress(){
        *ofstr << "\t<xyz>\n";
        *ofstr << "\t</xyz>\n";
        *ofstr << " who=\"";
        *ofstr << "/>\n";
    written = true;
    /* "lastsucessfulwrite" How to store the index of ofstr , in case of normal files we use ftell but in DeflatingOutputStream how to get index so that I can erase it later based on this value */
    }

    timer(){
    sleep(2);
    // 2 second 
    written = false ;
    }

    close(){
        ofstr->close();
        delete ofstr;
        ofstr = NULL;
        ostr->close();
        delete ostr;
        ostr = NULL;
    }


    int main(){

        ostr = new std::ofstream;
        ostr->exceptions(std::ofstream::failbit|std::ofstream::badbit);
        ostr->open(_fileName.c_str(), std::ios::binary | std::ios::app);
        ofstr = new Poco::DeflatingOutputStream(*_ostr,         
        Poco::DeflatingStreamBuf::STREAM_GZIP);
        ofstr->precision(std::numeric_limits<double>::digits10);
        string data1 = "hello';
        string data2 = "hello';
        string data3 = "hello';
    written = false ;
    timer()//start
    compress(data1);
    if(written)
    {
    compress(data2);
    }

    if(written)
    {
    compress(data2);
    }

    if(written)
    {
    compress(data3);// timeup and time() is inovked and part of compress() is executed 
    }
    // Now I would like to use lastsucessfulwrite as the key and truncate the paritally witten data3
    // In case of normal file we use "truncate" system call

     close();
    }
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
std::ofstream*ostr;
Poco::放气输出流*ofstr;
字符串fileName=“/home/lamb/Cpp/simple.gzip”;
bool-writed=false;
//最后一次成功写入;
压缩(){

* OFSTR

可以使用任何具有POCO流的标准C++流函数。


streampos pos=ofstr->tellp()

您好,有人能帮我解决上述问题吗?有没有类似于truncate的方法可以使用放气流中的位置擦除数据?