I wrote my implementation of printf – myPrintf,which prints to stdout.
I want to verify that it works fine.In order to check the correctess of the printed output I want to compare it with char I expect to get. How can I write code to redirect the stdout to buffer,not using >.
I can use only printf!
You could redirect
coutsbuffer by setting it’srdbuf()to a file you have opened.Weird, C++ and only printf, but whatever.
It’s also possible to redirect stdout in C.
Here is one way of doing it: https://rydow.wordpress.com/2007/10/26/c-code-to-redirect-stdout/
It involves
dupanddup2.There is also this option ( Rerouting stdin and stdout from C ) using
freopen.