Backto C/C++ Index
引入头文件
#include <fstream>
然后 Read 用 ifstream
, Write 用 ofstream
ifstream infile;
ofstream outfile;
// common operarions
file.open("file_path.text", MODE);
// do your bussiness here
file.flush(); // if write
file.close();
更简介高级的方式,还是使用封装好的库吧.比如
Ref
- C++中Txt文件读取和写入 : 知识点讲解,排版很乱
- c++对txt文件的读取与写入 : 例子可以, 直接copy过来改一下场景就可以用