Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 2.16 KB

text-and-binary-mode-file-i-o.md

File metadata and controls

23 lines (16 loc) · 2.16 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: Text and Binary Mode File I/O
Text and Binary Mode File I/O
04/11/2018
files [C++], open functions
I/O [CRT], text files
functions [CRT], file access
binary access, binary mode file I/O
translation, modes
I/O [CRT], binary
text files, I/O
I/O [CRT], translation modes
translation modes (file I/O)
binary access
3196e321-8b87-4609-b302-cd6f3c516051

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 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