I'm not sure whether fstream::sync (or stdio fflush)
calls this function; I think those functions just
flush data from the C or C++ library buffering, to
the operating system. The FlushFileBuffers causes
the operating system to ensure the data has been
sent to the disk.
>
>Is it possible to obtain a Windows HANDLE for a file
>that I've opened as a C++ fstream, so that I can call
>FlushFileBuffers on it?
No. There is no standard way AFAIK to do that.
Standard says that all I/O functions (opening, closing, reading and
writing) are forwarded to the std::basic_filebuf class. Common
implementation of this class uses C file streams for all operations.
That is the case with Dinkumware, RW and stlport.
The only thing you can do is to implement your custom version of file
stream which would generaly mean you will need to create your version
of basic_filebuf class and new version of fstream class that uses that
new version of basic_filebuf for I/O.
In that implementation you will have to use CreateFile/CloseHandle and
other respective windows API functions.
As a starting point take a look at this article:
That's correct. For now at least. There is some effort to add support
for this in the next C++ standard, along the lines of the Classic
Iostream
functions fd(), attach(), and detach(). These extensions have already
been implemented in the Apache C++ Standard Library. See
http://incubator.apache.org/stdcxx/doc/stdlibref/basic-filebuf.html#idx51
> Standard says that all I/O functions (opening, closing, reading and
> writing) are forwarded to the std::basic_filebuf class. Common
> implementation of this class uses C file streams for all operations.
> That is the case with Dinkumware, RW and stlport.
The latest Rogue Wave implementation of the C++ Standard Library
(as well as Apache stdcxx that was derived from it) is based on the
native file I/O (i.e., POSIX read/write or the Windows API), although
the library can be configured to use stdio instead as an option. On
most operating systems these "native" calls are faster.