#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;
}
के बफर flushes के बाद मैं संकलन और उपरोक्त कार्यक्रम चलाने के लिए, यह उत्पादन होता है है:क्यों cerr अदालत
hello couthello cerr
All done
लेकिन मुझे लगता है यह होना चाहिए:
hello cerrhello cout
All done
मैं करना चाहते हैं पता है, क्यों cerr
cout
के बफर को फहराता है?
'cout <<" हैलो कोउट ";' सीर << "हैलो सीर" से पहले आता है; ' – iammilind
मैं जानना चाहता हूं कि क्यों सीओटी का उत्पादन सीर से पहले आता है। मुझे लगता है कि कोउट का उत्पादन buffered है, सीर का उत्पादन पहले – wildpointercs