Cbeam
Loading...
Searching...
No Matches
cbeam::filesystem::stdout_redirector Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ stdout_redirector()

cbeam::filesystem::stdout_redirector::stdout_redirector ( const std::filesystem::path & file_path)
inlineexplicit

Constructor that redirects stdout to the specified file.

Parameters
file_pathThe path of the file to redirect stdout to.

◆ ~stdout_redirector()

virtual cbeam::filesystem::stdout_redirector::~stdout_redirector ( )
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.


The documentation for this class was generated from the following file: