Why doesn't Createfile() have a binary flag
One of the great joys of windows programming is remembering to put 'wb' or 'rb' or ios::binary i开发者_JAVA百科n all the file open calls so that Windows doesn't merrily convert all your 0x13s.
I just had to convert a bunch of nicely standard code to use Createfile() to get a certain flag - and it occurred to me that there is no way to specify binary.
How does it know? I really don't want it changing bytes in my MP4 stream thank-you-very-much.Because CreateFile doesn't do "text-mode"/newline conversions. Those are handled at a higher level, either in FILE for the CRT or iostreams for C++.
Everything is binary as far as the Windows API is concerned. Personally I prefer it that way. I never use the "text mode" in the standard library stuff.
You can't specify a binary or text flag, because to the Windows OS, all files are binary! The wb and rb options are introduced as a nicety, as part of the C IO stream functionality, and even then only on DOS / Windows, to help the developer read and write text files and perform CR/LF to LF conversion.
精彩评论