#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;
}
的缓冲后,我编译和运行上面的程序,它的输出是:为什么CERR刷新COUT
hello couthello cerr
All done
,但我认为它应该是:
hello cerrhello cout
All done
我想知道,为什么cerr
冲刷了cout
的缓冲区?
'cout <<“hello cout”;'before before'cerr <<“hello cerr”;' – iammilind 2011-05-17 06:28:37
我想知道为什么cout的输出会在cerr之前出现。我认为cout的输出是缓冲的,cerr的输出应该先出来 – wildpointercs 2011-05-17 06:30:58