1.txt里的我全部转换到3.txt里,没另建文件了
代码如下:
#include
using namespace std;
#include
int main()
{
ifstream infile1("1.txt",ios::in);
if (!infile1)
{
cerr<<"open error!"<
}
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!"<
}
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!"<
}
int i=0,j=0;int flag=1;
while (flag)
{i=0;
for(;i<10;i++){
outfile.put(letter2[i]);
}
while(letter2[i]!='\0')
{
outfile.put(letter2[i]);
if(letter2[i-9]=='r'&&letter2[i-8]=='e'&&letter2[i-7]=='s'&&letter2[i-6]=='u'&&letter2[i-5]=='l'&&letter2[i-4]=='t'&&letter2[i-3]==' '&&letter2[i-2]=='i'&&letter2[i-1]=='s'&&letter2[i]==' ')
{
for(int l=0;l<4;l++)
{
if(letter1[j]=='\0')
{
flag=0;
break;
}
outfile.put(letter1[j]);
j++;
}
while(letter2[i+1]!='\n')
i++;
}
i++;
}
}
infile1.close();
infile2.close();
outfile.close();
return 0;
}
应该那么写,不过你写的条件也不是很明晰,而且50分有点少,呵呵。
希望看到TXT文件的内容,ljupcn@163.com