I want to redirect the output of
perror to a file. What is the best way to do that?
You mean I can use this statement in a C++ program?
You're asking the wrong question.
Use strerror to write the text to a buffer, then you do what you like with it.
interesting discussion ... i have no any idea...