int main(void) {
ifstream InputFile;
ofstream OutputFile;
if (OpenInputFile(InputFile) && OpenOutputFile(OutputFile)) {
CopyIntegers(InputFile, OutputFile);
InputFile.close();
OutputFile.close();
}
else
cout << "Error opening file" << endl;
return(0);
}
//----------------------------------------
CopyIntegers(ifstream &InputFile, ofstream &OutputFile) {
int Data;
InputFile >> Data;
while (!InputFile.eof())
{
OutputFile << Data << " ";
InputFile >> Data;
}
}
|
//----------------------------------------
boolean OpenInputFile(ifstream &InputFile) {
string InputFileName;
cout << "Enter the input file name: ";
cin >> InputFileName;
InputFile.open(InputFileName);
return(!InputFile.fail());
}
//----------------------------------------
boolean OpenOutputFile(ofstream &OutputFile) {
string OutputFileName;
cout << "Enter the output file name: ";
cin >> OutputFileName;
OutputFile.open(OutputFileName);
return(!OutputFile.fail());
}
|