// Bob Myers // // copy.cpp // copies an input file to an output file, character by character #include #include // for setw #include // for ifstream, ofstream using namespace std; int main() { char filename[25]; char ch; ifstream in1; // input file stream ofstream out1; // an output file stream do { in1.clear(); cout << "Please enter the name of the input file.\n"; cout << "Filename: "; cin >> setw(25) >> filename; in1.open(filename); if (!in1) cout << "That is not a valid file. Try again!\n"; } while (!in1); do { out1.clear(); cout << "Please enter the name of the output file.\n"; cout << "Filename: "; cin >> setw(25) >> filename; out1.open(filename); if (!out1) cout << "That is not a valid file. Try again!\n"; } while (!out1); // PROCESS THE FILES // Read a character from input, write a character to output while (!in1.eof()) // while not end of input file { in1.get(ch); // read a character from input file using get() out1 << ch; // write that character to output file } in1.close(); out1.close(); cout << "Processing complete\n"; return 0; }