Editare

Partajați prin


Text and binary mode file I/O

File I/O operations take place in one of two translation modes, text or binary, depending on the mode in which the file is opened. Data files are often processed in text mode. To control the file translation mode, one can:

  • Retain the current default setting and specify the alternative mode only when you open selected files.

  • Use the function _set_fmode to change the default mode for newly opened files. Use _get_fmode to find the current default mode. The initial default setting is ANSI text mode (_O_TEXT).

  • Change the default translation mode directly by setting the global variable _fmode in your program. The function _set_fmode sets the value of this variable, but it can also be set directly.

When you call a file-open function such as _open, fopen, fopen_s, freopen, freopen_s, _fsopen or _sopen_s, you can override the current default setting of _fmode by specifying the appropriate argument to the function _set_fmode. The stdin, stdout, and stderr streams always open in text mode by default; you can also override this default when opening any of these files. Use _setmode to change the translation mode using the file descriptor after the file is open.

See also

Input and output
Universal C runtime routines by category