// Attached: HW_6b
// ===========================================================
// File: HW_6b.cpp
// ===========================================================
// Programmer: Elaine Torrez
// Class: CS 1A
// ===========================================================
#include <iostream>
#include <fstream>
using namespace std;
// ==== main ===================================================
// This program reads numbers from the data.txt file and
// writes them to the results.txt file.
//
// Input:
// data.txt - A text file containing integer values.
//
// Output:
// The numbers are written to results.txt, and a message
// is displayed on the screen.
// ===========================================================
int main()
{
ifstream inFile;
ofstream outFile;
int number;
// open the input and output files
inFile.open("data.txt");
outFile.open("results.txt");
// check if the input file opened successfully
if (!inFile)
{
cout << "Error opening file!" << endl;
return 0;
}
// write each number from data.txt into results.txt
while (inFile >> number)
{
outFile << number << endl;
}
inFile.close();
outFile.close();
cout << "The data has been written to the file." << endl;
cout << "Press any key to continue . . .";
cin.get();
return 0;
} // end of main()
// ===========================================================