fseek函数会在C ++中刷新缓冲区中的数据吗? [英] Will fseek function flush data in the buffer in C++?

查看:171
本文介绍了fseek函数会在C ++中刷新缓冲区中的数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道对fprintf或fwrite之类的函数的调用不会立即将数据写入磁盘,而是将对数据进行缓冲,直到达到阈值为止.我的问题是,如果我调用fseek函数,这些缓冲的数据是否会在寻求新位置之前写入磁盘?还是数据仍在缓冲区中,并被写入新位置?

We know that call to functions like fprintf or fwrite will not write data to the disk immediately, instead, the data will be buffered until a threshold is reached. My question is, if I call the fseek function, will these buffered data writen to disk before seeking to the new position? Or the data is still in the buffer, and is writen to the new position?

cheng

推荐答案

我不知道是否保证缓冲区会被刷新,如果您寻找到足够接近的位置则可能不会.但是,无法将缓冲的数据写入新位置.缓冲只是一种优化,因此必须透明.

I'm not aware if the buffer is guaranteed to be flushed, it may not if you seek to a position close enough. However there is no way that the buffered data will be written to the new position. The buffering is just an optimization, and as such it has to be transparent.

这篇关于fseek函数会在C ++中刷新缓冲区中的数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆