/////////////////////////////////////////////////////////////// // exmp1h.cpp - reading input from files and writing // // output to files and console // // Jim Fawcett, ELE591\791, Su'99 // // build: cl /GX exmp1h.cpp // /////////////////////////////////////////////////////////////// #include // C++ terminal I/O library #include // C++ file I/O library #include // C++ string library using namespace std; void main(int argc, char *argv[]) { cout << "\n Read and Write Using Files " << "\n ============================ "; if(argc == 1) { cout << "\n\n Please enter the name of a file to read\n\n"; return; } ifstream inStream(argv[1]); if(!inStream.good()) { cout << "\n\n Can't open file " << argv[1] << " for reading\n\n"; return; } if(argc == 2) { cout << "\n\n Please enter the name of a destination file\n\n"; return; } ofstream outStream(argv[2]); if(!outStream.good()) { cout << "\n\n Can't open file " << argv[2] << " for writing\n\n"; return; } else cout << "\n\n Copying " << argv[1] << " to " << argv[2] << "\n\n"; char ch; while(inStream.good()) { inStream.get(ch); outStream << ch; } }