std:: clog, std:: wclog
|
定义于头文件
<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 << "constructor\n"; } ~Foo() { std::clog << "destructor\n"; } }; Foo f; // 静态对象 int main() { std::clog << "main function\n"; }
输出:
constructor main function destructor
参见
|
初始化标准流对象
(
std::ios_base
的公开成员类)
|
|
|
写入标准 C 错误流
stderr
,无缓冲
(全局对象) |
|
|
写入标准 C 输出流
stdout
(全局对象) |
|
|
与输入流关联的
FILE
*
类型表达式
与输出流关联的 FILE * 类型表达式 与错误输出流关联的 FILE * 类型表达式 (宏常量) |