_flushall_flushall

刷新所有流;清除所有缓冲区。Flushes all streams; clears all buffers.

语法Syntax

int _flushall( void );

返回值Return Value

_flushall返回打开的流(输入和输出)的数量。_flushall returns the number of open streams (input and output). 无错误返回。There is no error return.

备注Remarks

默认情况下, _flushall函数会将与打开的输出流关联的所有缓冲区的内容写入相应的文件中。By default, the _flushall function writes to appropriate files the contents of all buffers associated with open output streams. 与打开的输入流关联的所有缓冲区的当前内容将被清除。All buffers associated with open input streams are cleared of their current contents. (这些缓冲区通常由操作系统维护,操作系统确定将数据自动写入磁盘的最佳时间:当缓冲区已满时、当流已关闭时或当程序在未关闭流的情况下正常终止时。)(These buffers are normally maintained by the operating system, which determines the optimal time to write the data automatically to disk: when a buffer is full, when a stream is closed, or when a program terminates normally without closing streams.)

如果读取后跟对 _flushall的调用,则会将输入文件中的新数据读取到缓冲区中。If a read follows a call to _flushall, new data is read from the input files into the buffers. 调用 _flushall后,所有流将保持打开状态。All streams remain open after the call to _flushall.

利用运行库的提交到磁盘功能,您可以确保将关键数据直接写入磁盘而不是操作系统的缓冲区。The commit-to-disk feature of the run-time library lets you ensure that critical data is written directly to disk rather than to the operating system buffers. 无需重写现有程序,可以通过将程序的对象文件与 Commode.obj 链接来启用此功能。在生成的可执行文件中,对 _flushall的调用会将所有缓冲区的内容写入磁盘。Without rewriting an existing program, you can enable this feature by linking the program's object files with Commode.obj. In the resulting executable file, calls to _flushall write the contents of all buffers to disk. 只有 _flushallfflush受 commode.obj 影响。Only _flushall and fflush are affected by Commode.obj.

有关控制提交到磁盘功能的信息,请参阅流 I/Ofopen_fdopenFor information about controlling the commit-to-disk feature, see Stream I/O, fopen, and _fdopen.

要求Requirements

函数Function 必需的标头Required header
_flushall_flushall <stdio.h><stdio.h>

有关更多兼容性信息,请参阅 兼容性For more compatibility information, see Compatibility.

示例Example

// crt_flushall.c
// This program uses _flushall
// to flush all open buffers.

#include <stdio.h>

int main( void )
{
   int numflushed;

   numflushed = _flushall();
   printf( "There were %d streams flushed\n", numflushed );
}
There were 3 streams flushed

请参阅See also

流 I/OStream I/O
_commit_commit
fclose、_fcloseallfclose, _fcloseall
fflushfflush
setvbufsetvbuf