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.
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).
mystream << "Hello World" << std::endl
std::getline
On Windows, the only difference I noticed was mystream << "Hello World" << std::endlusing:
0x0D 0x0A
0x0A
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?
Consider stream as binary rather than text.
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?
fstream::seekg
- : , << >> ( ). , , , (, '\n') - undefined, .
<<
>>
'\n'
: 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.
.
, : Linux MacOS X . Windows , \n \r\n .
\n
\r\n