我在学习 C++,发现了一些我看不懂的东西:
Output buffers can be explicitly flushed to force the buffer to be written. By default, reading
cin
flushescout
;cout
is also flushed when the program ends normally.
所以刷新缓冲区(例如输出缓冲区):这是通过删除缓冲区中的所有内容来清除缓冲区,还是通过输出其中的所有内容来清除缓冲区?还是刷新缓冲区意味着完全不同的东西?
最佳答案
考虑写入文件。这是一项昂贵的操作。如果在您的代码中一次写入一个字节,那么每次写入一个字节将非常昂贵。因此,提高性能的一种常用方法是将正在写入的数据存储在临时缓冲区中。只有当有大量数据时才将缓冲区写入文件。通过推迟写入,一次写入一大块,性能得到了提升。
考虑到这一点,刷新缓冲区是将数据从缓冲区传输到文件的行为。
Does this clear the buffer by deleting everything in it or does it clear the buffer by outputting everything in it?
后者。
关于c++ - 刷新缓冲区是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15042849/