// ;----------------------------------------------------------- // ; Program Name: Class_Demo // ; File: demoprob22.cpp // ; Description: Shows use of good(), rdstate() Member Functions // ; and the Append Operation // ; Author: Jim Adams // ; Environment: MS C++ 6.0 // ; Date Written: 11/02/2001 // ;----------------------------------------------------------- #include #include char num[20]; void main(void) { char data_file[60]="C:/DATA/C_PROGRAMS/CIS162/FALL2001/NUMBERS.DAT"; char new_file[60] ="C:/DATA/C_PROGRAMS/CIS162/FALL2001/NEWDATA.DAT"; ifstream numbers_in; ofstream numbers_out; // Open the input file numbers_in.open(data_file, ios::in | ios::nocreate); if (numbers_in.good() == false) { cout << "Error Opening input File " << data_file << " \n\n"; exit(1); } // Open the output file for append numbers_out.open(new_file, ios::app); if (numbers_out.good() == false) { cout << "Error Opening Output File " << new_file << " \n\n"; exit(1); } // Read and write the data while (! numbers_in.eof()) { numbers_in >> num; numbers_out << num << endl; cout << num << " " << numbers_in.rdstate() << endl; } // Close the files numbers_in.close(); numbers_out.close(); }