# 只读模式with open ( "file.txt" ,'r' ) as f: for line in f.readlines(): print ( line )# 读写,可以写,内容在文件最开头with open ( "file.txt" ,'r+' ) as f: #for line in f.readlines(): f.write('r+ ...') # w : 普通的写模式,如文件…
1.向文件写数据 头文件#include <ofstream> ①Create an instance of ofstream(创建ofstream实例) ②Open the file with open() or ofstreamconstructor (用open()或者构造函数打开文件) ③Writedata to the file with "<<" (用流插入运算符写数据) ④Close the file (explicitly close()) (显…