Hello all,
I am running into some odd "quirks" of the
filtering_istream in the boost::iostreams library.
Perhaps I am
just using it wrong, but all code compiles, and does _almost_ what I
would expect it to.
Example Code:
#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/invert.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <iostream>
int main()
{
boost::iostreams::file log_file("sample.txt", std::ios::trunc);
boost::iostreams::filtering_istream in;
in.push( boost::iostreams::invert(boost::iostreams::tee(log_file)) ) /* this part is optional */
in.push( std::cin );
std::string s;
int i;
/* step 1 */
getline(std::cin,s); /* note: std::cin as istream passed to getline */
std::cin >> i;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
std::cout << s << std::endl << i << std::endl;
/* step 2 */
getline(in,s); /* note: filtering_istream wrapping std::cin passed here */
in >> i;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
std::cout << s << std::endl << i << std::endl;
/* I would expect step 1 and step 2 to behave exactly the same (except for the loggin) */
}