Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图弄清楚打开文件之间的区别:
fstream *fileName*("FILE.dat",ios::binary);
或者
fstream *fileName*("FILE.dat",ios::out);
fstream *fileName*("FILE.dat",ios::binary | ios::out);
我发现所有这些形式都是相同的:在所有情况下,文件上的相同输出都是使用*fileName*<<或生成的*fileName*.write()。
*fileName*<<
*fileName*.write()
ios::out打开文件进行写入。
ios::out
ios::binary确保读取或写入数据而无需即时转换换行符\r\n。换句话说,你给流的正是所写的。
ios::binary
\r\n
使用 ios::binary 打开文件控制如何处理换行符。在 Windows 上,它们被扩展为 CRLF 对。就是这样 - 它对 operator<< 之类的工作方式没有影响。