#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
int dataNums;
fstream dataFile;
fstream resultsFile;
//---------------------------------------------------------------------
dataFile.open("data2.txt", ios::in);
if (!dataFile)
{
cout << "\"data2.txt\" did not open. Now closing. \n";
exit(1);
}
while (!dataFile.eof())
{
dataFile >> dataNums;
}
//---------------------------------------------------------------------
resultsFile.open("results.txt", ios::out);
if (!resultsFile)
{
cout << "\"results.txt\" did not open. Now closing. \n";
exit(1);
}
resultsFile << dataNums;
cout << "The data has been written to \"results.txt\".";
cout << endl << endl;
//---------------------------------------------------------------------
dataFile.close();
resultsFile.close();
return 0;
}
/*
Output:
The data has been written to "results.txt".
Press any key to continue . . .
*/