用C++,学了输入输出流
编程C++,第6.7题
答案:2 悬赏:10
解决时间 2021-04-10 03:34
- 提问者网友:低唤何为爱
- 2021-04-09 04:56
最佳答案
- 二级知识专家网友:孤伤未赏
- 2021-04-09 05:38
6.
//#include "stdafx.h"//vc++6.0加上这一行.
#include
#include "stdlib.h"
#include
using namespace std;
void myfun(ifstream &ifile,ofstream &ofile){
char tmp[256];
while(ifile >> tmp,!ifile.eof())
ofile << tmp << ' ';
}
int main(void){
ifstream ifile("123.txt");
ofstream ofile("456.txt",ios::trunc);
if(!ifile || !ofile){
cout << "Open the file failure...\n";
exit(0);
}
myfun(ifile,ofile);
ifile.close();
ofile.close();
return 0;
}7.
//#include "stdafx.h"//vc++6.0加上这一行.
#include
#include "stdlib.h"
#include
using namespace std;
void mergefiles(ifstream &in1,ifstream &in2,ofstream &ofile){
int a,b,x=(1<
in2 >> b;
while(in1 >> a){
if(a<=b){
ofile << a << ' ';
continue;
}
else ofile << b << ' ';
while(in2 >> b){
if(b<=a) ofile << b << ' ';
else{
ofile << a << ' ';
break;
}
}
if(in2.eof()){
ofile << a << ' ';
b=x;
}
}
if(in1.eof())
while(in2 >> a)
ofile << a << ' ';
}
int main(void){
ifstream in1("123.txt"),in2("456.txt");
ofstream ofile("789.txt",ios::trunc);
if(!in1 || !in2 || !ofile){
cout << "Open the file failure...\n";
exit(0);
}
mergefiles(in1,in2,ofile);
in1.close();
in2.close();
ofile.close();
return 0;
}7的算法很臭,若需要,你就将就着用吧……
//#include "stdafx.h"//vc++6.0加上这一行.
#include
#include "stdlib.h"
#include
using namespace std;
void myfun(ifstream &ifile,ofstream &ofile){
char tmp[256];
while(ifile >> tmp,!ifile.eof())
ofile << tmp << ' ';
}
int main(void){
ifstream ifile("123.txt");
ofstream ofile("456.txt",ios::trunc);
if(!ifile || !ofile){
cout << "Open the file failure...\n";
exit(0);
}
myfun(ifile,ofile);
ifile.close();
ofile.close();
return 0;
}7.
//#include "stdafx.h"//vc++6.0加上这一行.
#include
#include "stdlib.h"
#include
using namespace std;
void mergefiles(ifstream &in1,ifstream &in2,ofstream &ofile){
int a,b,x=(1<
while(in1 >> a){
if(a<=b){
ofile << a << ' ';
continue;
}
else ofile << b << ' ';
while(in2 >> b){
if(b<=a) ofile << b << ' ';
else{
ofile << a << ' ';
break;
}
}
if(in2.eof()){
ofile << a << ' ';
b=x;
}
}
if(in1.eof())
while(in2 >> a)
ofile << a << ' ';
}
int main(void){
ifstream in1("123.txt"),in2("456.txt");
ofstream ofile("789.txt",ios::trunc);
if(!in1 || !in2 || !ofile){
cout << "Open the file failure...\n";
exit(0);
}
mergefiles(in1,in2,ofile);
in1.close();
in2.close();
ofile.close();
return 0;
}7的算法很臭,若需要,你就将就着用吧……
全部回答
- 1楼网友:无字情书
- 2021-04-09 06:19
没看懂什么意思?
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯