/* * * * * * * * * * * * * * * * * * * Name: Nathanael Paul Userid: nrpaul Section #: 0 Date: October 2, 2000 Program #: 51 Program Desc: Demonstrates file I/O * * * * * * * * * * * * * * * * * * * */ #include // cin, cout, endl #include // string #include // File I/O (ifstream and ofstream) using namespace std; /* * * * * * * * * * * * * * * * Name: int main() Parameters: none Description: Demonstrates file I/O * * * * * * * * * * * * * * * */ int main() { // create the file streams to do I/O ifstream inData; ofstream outData; string line; // open input.dat in order to do I/O inData.open("input.dat"); // test to see if successful at opening the file input.dat if(!inData) { cout << "Can't open the input file." << endl; return 1; } // open an output file outData.open("results.dat"); if(!outData) { cout << "Can't open the output file." << endl; return 1; } // read first part inData >> line; // read rest of file while(inData) { cout << "Reading data..." << endl; //inData >> line; cout << "Outputting data..." << endl; // outData << line << endl; cout << line << endl; // try commenting out the next line of code while uncommenting the // 6th line above it. What is different to results.dat? // why? inData >> line; } // close the files inData.close(); outData.close(); return 0; }