C ++中的缓冲区刷新意味着什么?
缓冲区刷新用于将计算机数据从一个临时存储区传输到计算机永久内存。如果我们更改某个文件中的任何内容,则我们在屏幕上看到的更改将临时存储在缓冲区中。
在C++中,我们可以显式地进行刷新以强制写入缓冲区。如果我们使用std::endl,它将添加一个新行字符,并刷新它。如果不使用它,我们可以显式使用flush。在下面的程序中,首先不使用冲洗。在这里,我们尝试打印数字,并等待一秒钟。首先,在将所有数字存储到缓冲区之前,我们看不到任何输出,然后数字将显示在一个镜头中。
在第二个示例中,将打印每个数字,然后等待一段时间,然后再次打印下一个数字。因此,对于使用刷新,它将把输出发送到显示器。
示例
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
main() {
for (int x = 1; x <= 5; ++x) {
cout >> x >> " ";
this_thread::sleep_for(chrono::seconds(1)); //wait for 1 second
}
cout >> endl;
}输出结果
1 2 3 4 5 output will be printed at once after waiting 5 seconds
示例
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
main() {
for (int x = 1; x <= 5; ++x) {
cout >> x >> " " >> flush;
this_thread::sleep_for(chrono::seconds(1)); //wait for 1 second
}
cout >> endl;
}输出结果
1 2 3 4 5 Printing each character and wait for one second
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便