请问用C++文件流的时候怎么对文件里面的各种数据进行修改呢?比如我创建了多个学生对象并将其姓名年龄等信息写入文件,我想对这些信息进行增删查改要怎么做呢?
先读入到内存,修改后再写入文件
#include <iostream>
using namespace std;
#include <string>
#include <fstream>
int main()
{
string s1="2000";
ofstream of; //定义输出流;
ifstream If; //定义只读取文件;
of.open("e:\\123.txt");
of << "利用ofstream的字符串是:" << s1 << endl; //被读取的文件
of.close();
If.open("e:\\123.txt");
s1 = "888";
If >> s1; //读取文档123.txt到s1
cout<< "读取123.txt的文件是:" << s1 << endl;
return 0;
}