求解一道C++题

来源:百度知道 编辑:UC知道 时间:2024/06/03 02:52:09
看下面这个程序:
#include <iostream>
#include <fstream>
using namespace std;

void open_input_file(ifstream& in_stream);
void open_output_file(ofstream& out_stream);
void close_input_file(ifstream& in_stream);
void close_out_file(ofstream& out_stream);
void output();

int number;

int main()
{
char choice;

ifstream fin;
ofstream fout;

do
{
open_input_file(fin);
close_input_file(fin);
output();
open_output_file(fout);
close_out_file(fout);

cout << "要继续吗?(Y/N)\n";
cin >> choice;
}while(choice=='Y');

return 0;
}

void open_input_file(ifstream& in_stream)
{
in_stream.open("atry_ins.txt");
if(in_stream.fail())
{
cout << "连接失败!\n";
exit(1);
}

i

#include <iostream>
#include <fstream>
using namespace std;

void open_input_file(ifstream& in_stream);
void open_output_file(ofstream& out_stream);
void close_input_file(ifstream& in_stream);
void close_out_file(ofstream& out_stream);
void output();

int number;

void main()
{
char choice;

ifstream fin;
ofstream fout;
for (int i=0;;i++) {
cout << "要继续吗?(Y/N)\n";
cin >> choice;
if(choice=='Y')
{
open_input_file(fin);
close_input_file(fin);
output();
open_output_file(fout);
close_out_file(fout);
}

else exit(0);
}
//return 0;
}

void open_input_file(ifstream& in_stream)
{
in_stream.open("atry_ins.txt");
if(in_stream.fail())
{
cout << "连接失败!\n";
//exit(1);
}

in_stream >> number;
}