【Cpp 基础】主动刷新 cout 缓存区

发布时间 2023-11-09 09:43:41作者: FBshark

使用额外的 “刷新” 功能(<<flush)来确保根据我们的要求显示输出。

// C++程序演示flush函数的使用
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
int main()
{
	for (int i = 1; i <= 5; ++i)
	{
		cout << i << " " << flush;
		this_thread::sleep_for(chrono::seconds(1));
	}
return 0;
}