I have a Windows C++ program that is doing something like:
FILE* pf = ...; *stdout = *pf; // stdout is defined in stdio.h
I’m looking for an explanation about what happens when you change the value of the stdout file handle. Is this just a way of redirecting stdout?
-cr
If you change
stdoutby assignment instead of by using the tool designated (in C,freopen()as Adam Rosenfield said – and by extension, in C++), then you leave yourself open to all sorts of liabilities.coutwill also be redirected.pf, then you are liable for double-free errors (crashes).It is far better to do the job cleanly.
(Demo code isn’t necessarily written by, or even scrutinized by, the most experienced people in a vendor’s coding team. If it looks dubious, that may be because it is dubious.)