What is the use of std :: ios_base :: binary?

I am having trouble reading a Linux file in a window. Here is a discussion of the problem: Using fstream :: seekg under windows in a file created under Unix .

The problem was broken by opening the text file with the specified std::ios_base::binary.

But what is the actual point in this mode? If indicated, you can still work with the file as a text file (writing mystream << "Hello World" << std::endland reading with std::getline).

On Windows, the only difference I noticed was mystream << "Hello World" << std::endlusing:

  • 0x0D 0x0Aas a line separator, if std::ios_base::binarynot specified (EOL and carriage return)
  • 0x0Aas a line separator if specified std::ios_base::binary(EOL only)

Notepad does not show lines when opening files generated with std::ios_base::binary. Better editors like vi or Wordpad show them.

Is this the only difference between files generated with and without std::ios_base::binary? The documentation says Consider stream as binary rather than text.what does this mean at the end?

Is it safe to always install std::ios_base::binary, if I don’t care what you do in Notepad and want it to fstream::seekgalways work?

+4
source share
2 answers

- : , << >> ( ). , , , (, '\n') - undefined, .

: Unix ; . Windows, '\n' CR, LF (0x0D, 0x0A), 0x1A . ( ) , , , , . - : no '\n' .

std::ios_base::binary: - , , , . CR, LF, LF, . , Windows LF, Unix, CR, LF; , LF ( ). , , Unix Windows.

+6

.

, : Linux MacOS X . Windows , \n \r\n .

0

All Articles