std::clog, std::wclog
来自cppreference.com
输入/输出库
std::basic_ostream
全局对象 | |||||||
|
|||||||
成员函数 | |||||||
(C++11)
|
|||||||
有格式输出 | |||||||
无格式输出 | |||||||
定位 | |||||||
杂项 | |||||||
(C++11)
|
|||||||
成员类 | |||||||
非成员函数 | |||||||
在标头
<iostream>
定义
|
||
extern std::ostream clog;
|
(1) | |
extern std::wostream wclog;
|
(2) | |
全局对象 std::clog
和 std::wclog
控制实现定义类型(导出自 std::streambuf
)的流缓冲,与标准 C 输出流 stderr 关联,但不同于
std::cerr/std::wcerr ,不自动冲入这些流,且不自动与
cout tie() 。
保证这些对象在构造首个 std::ios_base::Init 类型对象之前或期间得到初始化,而且可用于带有序初始化的静态对象的构造函数和析构函数(只要在定义对象前包含
<iostream>
)。
除非发出 sync_with_stdio(false) ,有格式和无格式输出从多个线程访问这些对象是安全的。
注解
名称中的 'c' 指代“字符”( stroustrup.com FAQ );
clog
表示“字符日志”而 wclog
表示“宽字符日志”。
示例
运行此代码
#include <iostream> struct Foo { int n; Foo() { std::clog << "static constructor\n"; } ~Foo() { std::clog << "static destructor\n"; } }; Foo f; // 静态对象 int main() { std::clog << "main function\n"; }
输出:
static constructor main function static destructor
参阅
初始化标准流对象 ( std::ios_base 的公开成员类) |
|
写入到标准 C 错误流 stderr,无缓冲 (全局对象) |
|
写入到标准 C 输出流 stdout (全局对象) |
|
与输入流关联到 FILE* 类型表达式与输出流关联的 FILE* 类型表达式与错误输出流关联的 FILE* 类型表达式 (宏常量) |