关于fstream、ifstream、ofstream读写文本文件、二进制文件详解

fstream、ifstream、ofstream是c++中关于文件操作的三个类

fstream类对文件进行读操作和写操作

打开文件

fstream fs("要打开的文件名",打开方式);
或者
fstream fs;
fs.open("要打开的文件名",打开方式);

例子:

  • fstream fs("test.txt"); //用文本方式打开一个文件用于读写
  • fstream fs("test.txt",ios::binary); //用二进制方式打开一个文件用于读写
posted @ 2018-06-29 20:38  JohnRed  阅读(1085)  评论(0编辑  收藏  举报