I want to write a program and enable the user to have control over the logging of the package by setting the program to display progress or disable that.
I know that std::cout
is an std::ostream
with the difference that std::cout
redirects the results to standard output.
I want my class to have an std::ostream
member that I log everything to. Then if the user enables display, that member will be attached to std::cout
and displays the results, otherwise it wont.
What I have in mind is something similar to this:
class log {
private:
std::ostream display;
public:
void func();
void show_display();
}
void log::func(){
display << "called by func";
}
void log::show_display(){
// redirect display to standard output
}
Is there any way similar to above to do this? If not, how can I have similar results?
Thanks.