Is there a way to redirect C ++ output inside the code? The situation is that I use some external .cpp and .h files that use printf to put warnings in the console. I want to redirect only these outputs (not mine) to a file without changing my code.
So, in my program, I can redirect the output to a file, and when I add the output redirection to the console again by default, then the file again, and so on ...
Is it possible?
You can use freopen () for stdout to redirect stdout to a file.
printf 1, , fd, , 1, fd , .
close(1);, int fd = open(file); fd 1, - . , fd 1, .
close(1);
int fd = open(file);
, lowest available file descriptor number, 1, , printf.
lowest available file descriptor number
@roe, dup() 1 , fd, stdout.