开发者

What's the difference between opening a file with ios::binary or ios::out or both?

开发者 https://www.devze.com 2022-12-19 19:23 出处:网络
I\'m trying to figure out the difference between opening a file like: fstream *fileName*(\"FILE.dat\",ios::binary);

I'm trying to figure out the difference between opening a file like:

fstream *fileName*("FILE.dat",ios::binary);

or

开发者_JAVA技巧
fstream *fileName*("FILE.dat",ios::out);

or

fstream *fileName*("FILE.dat",ios::binary | ios::out);

I found that all of these forms are identical: in all cases, the same output on the file is produced using either *fileName*<< or *fileName*.write().


ios::out opens the file for writing.

ios::binary makes sure the data is read or written without translating new line characters to and from \r\n on the fly. In other words, exactly what you give the stream is exactly what's written.


Opening a file with ios::binary controls how newline characters are handled. On Windows, they are expanded to CRLF pairs. That's it - it has no effect on how things like operator<< work.

0

精彩评论

暂无评论...
验证码 换一张
取 消