书中页数:P282
代码名称:buf.cc
#include <iostream>
using std::endl; using std::flush; using std::ends;
using std::unitbuf; using std::nounitbuf; using std::cout;
int main()
{
// writes hi and a newline, then flushes the buffer
cout << "hi!" << endl;
// writes hi, then flushes the buffer; adds no data
cout << "hi!" << flush;
// writes hi and a null, then flushes the buffer
cout << "hi!" << ends;
cout << unitbuf; // all writes will be flushed immediately
// any output is flushed immediately, no buffering
cout << "first" << " second" << endl;
cout << nounitbuf; // returns to normal buffering
return 0;
}
594

被折叠的 条评论
为什么被折叠?



