///////////////////////////////////////////////////////////////////////////////////// // // Program: Retrieve the Source for this Program and Write it to the screen. // // Author: William F. Slater, III // // Description: The output of this program is its own source code. // // // // Date: September 2, 2003 // // File Name: CSS561-Extra--William_Slater.cpp // ///////////////////////////////////////////////////////////////////////////////////// #include #include #include #include void main() { // Declare variables char answer; // char variable to ask user if they want to repeat a run answer = 'y'; // variable to help re-run the program std::fstream fin, fout; // input and output file objects std::string str; // output string object // Section for Printing Heading cout << "===================================================================" << endl; cout << " **** Welcome to the Program that Writes Its Own Source Code! **** " << endl; cout << "This program will open its own source code text file and print it " << endl; cout << "to the screen, and close it." << endl; cout << "===================================================================" << endl; cout << endl; cout << endl; // Remain in loop as long as user wants to run the program while (answer != 'n') { // Open the new file for input to screen cout << "Opening the file named CSS561-Extra--William_Slater.cpp in C: root direcctory..." << endl; cout << endl; fin.open("c:/CSS561-Extra--William_Slater.cpp", std::ios::in); // Test to see if file was successfully opened. if (!fin.is_open()) { cout << "ERROR - Could not open the file." << endl; return(0); } // Read and display all text from the file cout << "Reading test from the file..." << endl; cout << endl; while (!fin.eof()) { std::getline(fin, str, '\n'); std::cout << str << std::endl; } cout << "Closing the file again..." << endl; cout << endl; fin.close(); // Ask if we want to run this baby again... cout << "Want to run again? (y for yes, n for no) " ; cin >> answer; } // End of big While loop cout << endl; cout << "*** Program is terminating *** " << endl; cout << endl; cout << " **** Thank you for your time... Goodbye! **** " << endl; } // End of main()