对文件的操作

孤单总是难免的 / 2023-05-03 / 原文

/*
ifstream 读文件
ofstream 写文件
fstream 读写文件

这个三个的头文件是 fstreamofstream outfile;
*/

写文件 

ofstream  h1;  /fstream h1

h1.open("user.txt");

h1<<name<<"\t" ;//"\t" 换行

h1 << age << endl;  //endl 表示换行

h1.close();

 

读文件

ifstream h2; // fstream  h2

h2.open("user.txt");

h2>>name;

h2>>age;

h2.close();