私は2つの異なるostreamを持っています。そのうちの1つは同じストリームバッファを使用するcerrです。いくつかのライブラリがあり、cerrを何らかの方法で変更した可能性があります(フラグ?フォーマット修飾子?)。
cerr.rdbuf(&mystreambuffer);
ostream teststream(&mystreambuffer);
cerr << "This " << " is " << " a " << " test";
teststream << "This " << " is " << " a teststream " << " test";
プリント:
This
is
a
test
This is a teststream test
デバッグテストストリームがまったく呼び出さないのに、cerrがすべての操作をmystreambuffer
呼び出すことに気づきました。
私が正しければ、それは単なる標準的なostreamですが、なぜフラッシング時間にこの違いが見られるのですか?cerrを通常のフラッシュ操作にリセットするにはどうすればよいですか?mystreambuffer->sync()
<<
cerr
編集:皆さんがunitbufについてコメントしていて、それがcerrでデフォルトになっているのを見ますが、デフォルトの場合は、ここでも段階的に記述しませんか?
#include <iostream>
int main(){
std::cerr << "This " << " is " << " a cerr " << " test\n";
std::cout << "This " << " is " << " a cout " << " test\n";
}
Cobain /tmp$ ./test
This is a cerr test
This is a cout test