I\'d like to overload << operator to write the value it takes to a file and cout. I have tried to do it with following code, but couldn\'t succeed it. It just writes t
If you are able to use it, you will find that, not unsurprisingly, the boost library has already done most of the hard work for you.
#include
#include
#include
#include
typedef boost::iostreams::tee_device teedev;
typedef boost::iostreams::stream, std::allocator< typename std::ostream::char_type > > tee_stream;
int main(int argc, char* argv[])
{
std::ofstream of;
of.open( "test.txt" );
teedev td( of, std::cout );
tee_stream ts(td);
ts << "!!!Hello World!!!" << std::endl;
return 0;
}