您的位置:首页 > 编程语言 > C语言/C++

C++primer plus第六版课后编程题答案17.4

2014-04-29 09:15 543 查看
main174.cpp

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main174()
{
ifstream fin1("input1.txt");
ifstream fin2("input2.txt");
ofstream fout("output.txt");
if(!fin1.is_open())
cout<<" input1.txt open failure!"<<endl;
if(!fin2.is_open())
cout<<" input2.txt open failure!"<<endl;
if(!fout.is_open())
cout<<" output.txt open failure!"<<endl;

string temp;
while(fin1.good()&&fin2.good())
{
getline(fin1,temp);
fout<<temp;
fout<<" ";
getline(fin2,temp);
fout<<temp;
fout<<endl;
}
if(fin1.eof()&&!fin2.eof())//1完了,2没完
{
while(fin2.good())
{
getline(fin2,temp);
fout<<temp;
fout<<endl;
}
}
if(fin2.eof()&&!fin1.eof())
{
while(fin1.good())
{
getline(fin1,temp);
fout<<temp;
fout<<endl;
}
}
if(fin1.eof()&&fin2.eof())
cout<<"copy complete!"<<endl;
else
cout<<"something bad!"<<endl;
fin1.close();
fin2.close();
fout.close();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息