I had a issue with Linux file reading under Window. Here is the issue discussion: Using fstream::seekg under windows on a file created under Unix.
The issue was workarounded by opening the text file with std::ios_base::binary
specified.
But what's the actual point with this mode? If specified, you can still work with your file as a text file (writting with mystream << "Hello World" << std::endl
and reading with std::getline
).
Under Windows, the only difference, I could notice is that mystream << "Hello World" << std::endl
uses:
0x0D 0x0A
as line separator ifstd::ios_base::binary
was not specified (EOL and carriage return)0x0A
as line separator ifstd::ios_base::binary
was specified (EOL only)
Notepad does not smartly show lines when opening the files generated with std::ios_base::binary
. Better editors like vi or Wordpad does show them.
Is that really the only difference there is between files generated with and without std::ios_base::binary
? Documentation says Consider stream as binary rather than text.
, what does this mean in the end?
Is it safe to always set std::ios_base::binary
if I don't care about opeing the file in Notepad and want to have fstream::seekg
always work?
\0
characters in the strings too. In binary those are probably just outputted, while for non-binary they might be interpreted as a string terminator. – Campanile