std::cerr, std::wcerr
Min standard notice:
Header: <iostream>
The global objects std::cerr and std::wcerr control output to a stream buffer of implementation-defined type (derived from std::streambuf and std::wstreambuf, respectively), associated with the standard C error output stream stderr.
# Declarations
extern std::ostream cerr;
extern std::wostream wcerr;
# Notes
The ‘c’ in the name refers to “character” (stroustrup.com FAQ); cerr means “character error (stream)” and wcerr means “wide character error (stream)”.
# Example
#include <chrono>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
void f()
{
std::cout << "Output from thread...";
std::this_thread::sleep_for(2s);
std::cout << "...thread calls flush()" << std::endl;
}
int main()
{
std::jthread t1{f};
std::this_thread::sleep_for(1000ms);
std::clog << "This output from main is not tie()'d to cout\n";
std::cerr << "This output is tie()'d to cout\n";
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 455 | C++98 | std::cerr.tie() andstd::wcerr.tie() returned null pointers | they return &std::cout and&std::wcout respectively |