qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::cout Class Reference

Thread-safe console output class. More...

#include <io.h>

Public Member Functions

 cout ()=default
 Default constructor.
 cout (cout const &)=delete
 Deleted copy constructor.
 ~cout ()
 Destructor that flushes output.
template<typename T>
std::stringstream & operator<< (T const &data)
 Stream insertion operator.
std::stringstream & operator<< (std::ostream &(*manip)(std::ostream &))

Detailed Description

Thread-safe console output class.

This class provides a thread-safe wrapper around std::cout. It uses a mutex to ensure that output operations from multiple threads don't interleave, resulting in garbled output.

Example usage:

qb::io::cout() << "Thread " << thread_id << " is running";
Thread-safe console output class.
Definition io.h:100
Note
For production code, it's preferable to use the logging system rather than direct console output.

Constructor & Destructor Documentation

◆ ~cout()

qb::io::cout::~cout ( )

Destructor that flushes output.

When the cout object is destroyed, its buffered content is output to std::cout in a thread-safe manner.

Member Function Documentation

◆ operator<<()

template<typename T>
std::stringstream & qb::io::cout::operator<< ( T const & data)
inline

Stream insertion operator.

Allows data to be inserted into the output stream using the standard C++ stream insertion syntax.

Template Parameters
TType of data to insert
Parameters
dataThe data to insert
Returns
Reference to the internal stringstream