This question already has an answer here:
- What is the point of clog? 4 answers
I have a basic debug message in my code that prints a message as to what function is called.
#ifdef _DEBUG
std::clog << "message etc" << std::endl;
#endif
How do I redirect the output to send the message to a textfile?
You can set the buffer associated with
clog
that uses a file to save its data to.Here's a simple program that demonstrates the concept.
As far redirect means from outside the program code, it depends a bit on your shell syntax actually. According this reference
std::clog
is usually bound tostd::cerr
:So e.g. in bash you would do something like
Regarding redirecting programmatically, you can do it as mentioned in R Sahu's answer, or explained in the currently marked duplicate.