If the function performs its own file I / O, it will be tough (therefore, there is the concept of "separation of problems", which seems to be violated here). Overloading operator <<
will not help; there is no return value from a function for such an operator to place it anywhere.
If you can change the function, let it take an argument, which is the object ostream
to write to (by default, it can be cout
).
, std::cout
, cout.rdbuf(newbuffer)
std::cout
, .
-, freopen
dup2
stdout
( ) .
, , (.. cout.rdbuf
, freopen
dup2
), . , , , , - , , .