2009-05-04 55 views
2

我在想「鏈接」幾個C++ iostream來過濾輸入兩次。我正在使用gzstreams來讀取zlib壓縮文件,我正在考慮編碼從流中讀取並執行編碼轉換的流。也許通過傳遞一個打開的流作爲構造參數...你認爲這可能是最好的完成?鏈接C++流

+0

「鏈接」是什麼意思? – 2009-05-04 06:58:40

回答

6

我還沒有使用過這個,但是boost的filtering_stream可能會有所幫助。

作爲一個例子,我發現a mailing list postindent.hpp,這實現了縮進輸出一個輸出濾波器:

boost::iostreams::filtering_ostream out; 
indent_filter::push(out,2); 
out.push(std::cout); 

並使用它像這樣:

out << "Hello Filter!\n" 
    << indent_in 
    << "this is\n" 
    << "indented\n" 
    << indent_out 
    << "until here\n" 
    ; 

哪樣導致輸出:

Hello Filter! 
    this is 
    indented 
until here