在学习c++Primer第八章io类时看到了如下代码,对flush,ends,unitbuf,nounitbuf都不太熟悉于是查询了一下作用
endl:都比较熟悉了,是起换行作用,除此之外还有刷新缓冲区的效果
lush,ends,unitbuf:也都有刷新缓冲区的功能,而cout<<n是系统每隔一段进行刷新检测输出,由于时间比较短所以一般无法察觉,nounitbuf则是恢复到正常的缓冲方式
include <iostream>
#include <unistd.h>
//如果是windows系统选择#include <windows.h>
using std::flush;
using std::nounitbuf;
using std::unitbuf;
int main()
{
cout<<"Hi!"<<endl;
sleep(