boost :: iostreams를 사용하여 데이터를 압축하려고합니다.boost :: iostreams :: copy()는 소스를 닫지 만 싱크는 닫지 않습니다.
copy()에 대한 문서에서 두 개의 인수는 모두 끝에 템플릿 함수 close()을 호출하여 닫힙니다. 내 테스트 코드는 다음과 같습니다
#include <iostream>
#include <fstream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
using namespace std;
int main(void)
{
ifstream ifs("output", ios::binary);
ofstream ofs("output.boost.gz", ios::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::gzip_compressor());
out.push(ofs);
cout << (ifs.is_open() ? "ifs is opened" : "ifs not opened") << endl;
cout << (ofs.is_open() ? "ofs is opened" : "ofs not opened") << endl;
boost::iostreams::copy(ifs, out);
cout << (ifs.is_open() ? "ifs is opened" : "ifs not opened") << endl;
cout << (ofs.is_open() ? "ofs is opened" : "ofs not opened") << endl;
return 0;
}
이 시험 출력 :
ifs is opened
ofs is opened
ifs not opened
ofs is opened
당신은 OFS는 여전히 열려 있음을 볼 수 있습니다. 내 질문은 : 왜? boost :: iostreams :: close()는 filtering_streambuf 객체를 전달할 때 무엇을합니까?
위대한 대답, 감사합니다; 나는 문서의 어떤 부분이 문서화되어 있는지뿐만 아니라이 행동의이면에있는 이론적 근거를 이해하는 데 어려움을 겪고있다. 부스트 개발자에게이 질문에 대한 답변을 얻으려고 할 가치가 있다고 생각합니까? – fireboot
@fireboot 그렇게 생각합니다. 그것은 의도적 인 것처럼 보입니다. 문서는 *** [close'의 문서] (http://www.boost.org/doc/libs/1_55_0/libs/iostreams/doc/functions/close.html#template_params_devices)를 참조합니다. *** 닫을 수없는 어떤 것에 대해서도 "플러시"합니다. – sehe