// Bob Myers // // badcopy.cpp // attempt to copy one file to another, character by character // Doesn't really work as we would hope -- why? #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 >> ch; // read a character from input file out1 << ch; // write that character to output file } in1.close(); out1.close(); cout << "Processing complete\n"; return 0; }