Many C and C++ programs use data files for input and output. With DOS, data files are normally processed in text mode. In this mode, each carriage-return– line-feed (CR-LF) combination is translated into a single line-feed character during input. During output, each line-feed character is translated into a CR-LF combination.
Sometimes you may want to process a file without making those translations. In these cases you use binary mode, which suppresses CR-LF translations.
You can control the file translation mode in the following ways:
To process a few selected files in binary mode, while retaining the default text mode for most files, you can specify binary mode when you open the selected files. The fopen routine opens a file in binary mode when you specify the letter b in the access-mode string for the file. The _open routine opens a file in binary mode when you specify the _O_BINARY flag in the oflag argument. For more information about fopen and _open, see the reference description of each routine.
To process most or all files in binary mode, you can change the default mode to binary. The global variable _fmode controls the default translation mode, which is normally text. If you set _fmode to _O_BINARY, the default mode is binary except for stdaux and stdprn, which are opened in binary mode by default.
You can change the value of _fmode in two ways:
Link with the file BINMODE.OBJ (supplied with Microsoft C/C++). This changes the initial setting of _fmode to the _O_BINARY flag, causing all files except stdin, stdout, and stderr to be opened in binary mode.
Change the value of _fmode directly by setting it to the _O_BINARY flag in your program. This has the same effect as linking with BINMODE.OBJ.
You can still override the default mode (now binary) for a particular file by opening it in text mode. Specify the letter t when using fopen, or specify the _O_TEXT flag when using _open.
By default, the stdin, stdout, and stderr files are opened in text mode, and the stdaux and stdprn files are opened in binary mode. The _setmode routine allows you to change these defaults or change the mode of a file after it has been opened. See the reference description of _setmode for details.