私は圧縮ファイルのセットを持っています。私はすべてのファイルを解凍して1つの大きなファイルを作成する必要があります。下のコードは正常に動作していますが、ファイルが大きく、ファイルコンテンツの中間コピーを作成したくないため、std :: stringstreamを使用したくありません。ブーストを使用して複数のファイルを1つのファイルに解凍する
boost::iostreams::copy(inbuf, tempfile);
を直接使用しようとすると、ファイル(tmpfile)が自動的に閉じられます。コンテンツをコピーする方法はありますか?少なくとも、このファイルを自動的に閉じないようにすることはできますか?
std::ofstream tempfile("/tmp/extmpfile", std::ios::binary);
for (set<std::string>::iterator it = files.begin(); it != files.end(); ++it)
{
string filename(*it);
std::ifstream gzfile(filename.c_str(), std::ios::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::gzip_decompressor());
inbuf.push(gzfile);
//closes tempfile automatically!!
//boost::iostreams::copy(inbuf, tempfile);
std::stringstream out;
boost::iostreams::copy(inbuf, out);
tempfile << out.str();
}
tempfile.close();
目的のファイルの上に簡単な出力フィルタを使用しますか? –