부스트 필터링 _ 스트림에 대한 몇 가지 기본적인 질문. 나는 지금은 압축 된 ZIP 파일로 출력 부스트 filtering_stream을 사용하고 싶습니다 :: 표준의 매개 변수를 사용 기능 수십를 &std :: ofstream을 boost 필터링 _ 스트림으로 대체하기위한 Param 구문
void foo(std::ofstream& outStream)
{
// lots of operations, like this:
outStream << "various bits of text";
}
void StreamSomeTextToFile(char* fileName)
{
ofstream myFileStream(fileName, ios::out | ios::app | ios::binary);
foo(myFileStream);
myFileStream.close();
}
을 ofstream. 일반적으로 언급 된 필터링 및 압축 해제를위한 filtering_streams 테스트 코드는 컴파일, 링크 및 완벽하게 작동합니다.
void StreamSomeCompressedTextToFile(char* fileName)
{
ofstream myFileStream(destPath, std::ios_base::out | std::ios_base::app | std::ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::output> myCompressedFileStream;
myCompressedFileStream.push(boost::iostreams::zlib_compressor());
myCompressedFileStream.push(myFileStream);
foo(myCompressedFileStream); // I can't just pass myCompressedFileStream to foo(std::ofstream&), right?
myFileStream.close();
}
세 가지 질문 : 나는 filtering_stream을 대체하고 싶습니다
1) 마십시오 이전에 표준 받아 내 모든 기능 :: ofstream 지금 형 부스트의 매개 변수를 받아 들일 수 & outStream 필요 :: IOSTREAMS :: filtering_streambuf &? 또는 적절한 매개 변수 유형이있어 수많은 ("foo") 함수가 어느 유형의 스트림 유형에서도 작동 할 수 있습니까? 내 간단한 테스트의 경우
2), 나는 filtering_streambuf와 스트림 연산자 구문을 사용 할 수 없습니다 :
myCompressedFileStream << "some text";
이이 오류가 발생하지 : '연산자 < <'에 대한 일치를. , 나는 내가 후에 파일 "hello.z"을 찾을 수 있음을 혼동했다
error: 'class boost::iostreams::filtering_streambuf<boost::iostreams::output, char, std::char_traits<char>, std::allocator<char>, boost::iostreams::public_>' has no member named 'write
'
3) 일반적인 테스트 케이스 예제 코드 (아래)에서 : 나는 유사 쓰기와 오류를() 컴파일했다 만들어졌습니다. 압축 풀기 코드 (아래에도 있음)가이를 분명하게 참조합니다 - 어디에서 찾을 수 있습니까? 참고 : 위치가 마지막으로 발견되었다 :가/라이브러리/환경 설정했다/
void pack()
{
std::ofstream file("hello.z", std::ios_base::out | std::ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::zlib_compressor());
out.push(file);
char data[5] = {'a', 'b', 'c', 'd', 'e'};
boost::iostreams::copy(boost::iostreams::basic_array_source<char>(data, sizeof(data)), out);
file.close();
}
void unpack()
{
std::fstream file("hello.z", std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::zlib_decompressor());
in.push(file);
boost::iostreams::copy(in, std::cout);
}
BTW : 엑스 코드 3.2.6, GNU 4.0, OS X 10.6.8
위대한, 그리고 매우 도움이 - 아직 거기에 대해 아직도 혼란 스러워요 : filtering_streambuf에서 ostream 개체를 구축 : filtering_streambuf (myCompressedFileStream) 필요합니다 ofstream 정의 된 첫 번째 (myFileStream) 푸시 할 수 있도록 . myCompressedFileStream에서 ostream을 생성 한 다음 새로 생성 된 ostream으로 출력하면 파일은 비어 있습니다. – SMGreenfield