64,685
社区成员
发帖
与我相关
我的任务
分享
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ifstream iFs("d:\\yourfile.txt");
string stBuffer;
// 读取数据到string中
getline(iFs, stBuffer);
// 找出fds的位置
int iPos = stBuffer.find("fds");
// 用abcde替换fds
stBuffer.replace(iPos, strlen("fds"), "abcde");
// 创建新文件写入
ofstream oFs("d:\\yourfile.txt");
oFs << stBuffer;
}