main174.cpp
#include
#include
#include
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();
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案174/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!