打开一个文件与ios :: binary或ios :: out或两者有什么区别? [英] What's the difference between opening a file with ios::binary or ios::out or both?

查看:587
本文介绍了打开一个文件与ios :: binary或ios :: out或两者有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚打开一个文件之间的区别:

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

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

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

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

我发现所有这些形式都是相同的:在所有情况下,文件上的相同输出使用 * fileName * * fileName * .write()生成。

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 打开要写入的文件。

ios :: binary 确保读取或写入数据,而不会将新行字符转换为 \r \\\
。换句话说,你给的流正是你写的。

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.

这篇关于打开一个文件与ios :: binary或ios :: out或两者有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆