I'm having some problems with file writing under C++. I've tried using OFSTREAM, FOPEN, and _OPEN along with their respective write functions however they arent doing what I expect of them.

I'm trying to open a file for binary writing. If the file exists or not, who cares, just write over it with this new file. And if while writing an error occurs such as "disk space is full" or "media error" then mention it so that I can abort my current operation. OFSTREAM's write() doesnt seem able to do this with its BAD(), FAIL(), or GOOD() functions, nor does it have a bytes written value. FOPEN's fwrite() seems to always return back the "count" value regardless of how much it actually wrote. And _OPEN just seems picky about a file existing and writing over top of it.

Can someone provide me with properly working code for writing out a binary file to disk. If the filename already exists simply write over top. If disk space is full or a media error occurs return back an error so that i can take the appropriate action. For instance if I try to write the file to 3.5" diskette with 0 bytes free space return an error that the data was written in full.

I'm using MS Visual C++ 6, MS Windows 2000.

Thanks.