Cbeam
|
Class for redirecting stdout to a file and subsequently resetting it to the system's default state. More...
#include <stdout_redirector.hpp>
Public Member Functions | |
stdout_redirector (const std::filesystem::path &file_path) | |
Constructor that redirects stdout to the specified file. | |
virtual | ~stdout_redirector () noexcept |
Destructor that resets stdout to the system's default state. | |
Class for redirecting stdout to a file and subsequently resetting it to the system's default state.
This class redirects the standard output (stdout) to a specified file upon its construction. Upon destruction, it resets stdout back to the system's default standard output. This reset is to the system's default stdout regardless of whether stdout was originally redirected to another destination prior to the instantiation of this object.
|
inlineexplicit |
Constructor that redirects stdout to the specified file.
file_path | The path of the file to redirect stdout to. |
|
inlinevirtualnoexcept |
Destructor that resets stdout to the system's default state.
On destruction, stdout is reset to the system's default output. If this operation encounters an error, it will be logged rather than throwing an exception, due to the nature of destructors in C++. Moreover, the absence of the system's default stdout is a valid scenario, e.g. when the executable is launched through an IDE that imposes such restrictions.