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(); }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————