Domanda
Stavo pensando a " concatenamento " un paio di iostreams in c ++ insieme per filtrare due volte l'input. Sto usando gzstreams per leggere i file compressi zlib e stavo pensando di codificare uno stream che legge da uno stream ed esegue conversioni di codifica. Forse passando un flusso aperto come parametro del costruttore ... Come pensi che possa essere realizzato al meglio?
Soluzione
Non l'ho usato ma boost <
Ad esempio ho trovato un post della mailing list con indent.hpp , che implementa un filtro di output che rientra uscite:
boost::iostreams::filtering_ostream out;
indent_filter::push(out,2);
out.push(std::cout);
E usalo così:
out << "Hello Filter!\n"
<< indent_in
<< "this is\n"
<< "indented\n"
<< indent_out
<< "until here\n"
;
Che produrrà un output:
Hello Filter!
this is
indented
until here
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow