Is there a API (like dup) to duplicate fstream so it can

view story

http://stackoverflow.com – I want to write a stream into one FILE *fp at the same time the stream should be copied onto another fp too is there a better way to write my debug function by eliminating one fprintf? const int logflag=1; #define debug(args ...) if (logflag) { FILE *flog = fopen("test.log", "a+"); fprintf( flog, args); fclose(flog); } fprintf(stderr, args); int main() { debug("test"); // writes test into both stderr and flog debug("test2"); } (HowTos)