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

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

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

打开文件

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

例子:

  • fstream fs("test.txt"); //用文本方式打开一个文件用于读写
  • fstream fs("test.txt",ios::binary); //用二进制方式打开一个文件用于读写

猜你喜欢

转载自www.cnblogs.com/smallredness/p/9245353.html