std::clog, std::wclog
来自 cppreference.cn
定义于头文件 <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” 指的是 “character”(stroustrup.com FAQ);clog
的意思是 “character log”,而 wclog
的意思是 “wide character log”。
[编辑] 示例
运行此代码
#include <iostream> struct Foo { int n; Foo() { std::clog << "constructor\n"; } ~Foo() { std::clog << "destructor\n"; } }; Foo f; // static object int main() { std::clog << "main function\n"; }
输出
constructor main function destructor
[编辑] 参见
Init 初始化标准流对象 (std::ios_base 的公共成员类) | |
写入到标准 C 错误流 stderr,无缓冲 (全局对象) | |
写入到标准 C 输出流 stdout (全局对象) | |
与输入流关联的 FILE* 类型的表达式 与输出流关联的 FILE* 类型的表达式 与错误输出流关联的 FILE* 类型的表达式 (宏常量) |