将两个文件合并成一个文件出错,小白求指教
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int i = 1;
char a[1000], b[1000], c[1000], d[1000];
fstream file1("1.txt", ios::in | ios::out | ios::trunc);
fstream file2("2.txt", ios::in | ios::out | ios::trunc);
ofstream ofile("3.txt", ios::out | ios::app);
cout << "输入两行字符串分别存至file1和file2: " << endl;
cin.getline(a, 999);
file1 << a << endl;
while(!file1.eof())
{
file1.getline(c, 999);
ofile << c;
}
file1.close();
cin.getline(b, 999);
file2 << b << endl;
while(!file2.eof())
{
file2.getline(d, 999);
ofile << d;
}
file2.close();
ofile.close();
char tmp;
ifstream ifile3("3.txt", ios::in);
while(!ifile3.eof())
{
tmp = ifile3.get();
cout << tmp;
}
ifile3.close();
cout << endl;
system("pause");
return 0;
}