求助各位大侠一个关于在C++中实现TXT查找替换功能的程序

来源:百度知道 编辑:UC知道 时间:2024/05/18 06:20:17
有两个TXT,从一个中读入一些字符,然后分批替换到另一个TXT的“s=”后面
这种程序改怎么写?
百度HI,在线等

1.txt里的我全部转换到3.txt里,没另建文件了
代码如下:
#include <iostream>
using namespace std;
#include <fstream>
int main()
{
ifstream infile1("1.txt",ios::in);
if (!infile1)
{
cerr<<"open error!"<<endl;
exit(1);
}
char letter1[100000];
char ch;int count1=0;
while (infile1.get(ch))
{
letter1[count1]=ch;
count1++;
}
letter1[count1]=0;

ifstream infile2("2.txt",ios::in);
if (!infile2)
{
cerr<<"open error!"<<endl;
exit(1);
}
char letter2[100000];
int count2=0;
while (infile2.get(ch))
{
letter2[count2]=ch;
count2++;
}
letter2[count2]=0;

ofstream outfile("3.txt");
if (!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}

int i=0,j=0;int flag=1