#include <iostream> using std::cout; using std::endl; using std::cerr; #include <cstdio> int main( ) { char pbuffer[BUFSIZ]; setbuf(stdout,pbuffer); cout << "hello cout" ; sleep(5); cerr << "hello cerr"; sleep(5); cout << "\nAll done " << endl; sleep(5); return 0; }
在我编译并运行上面的程序之后,它的输出是:
hello couthello cerr All done
但我认为它应该是:
hello cerrhello cout All done
我想知道,为什么cerr刷新cout的缓冲区?