From: Jakub Newsgroups: comp.os.msdos.djgpp Subject: Help C++ program not doing what it says Date: Mon, 27 Apr 1998 14:44:47 +1000 Organization: DIALix Internet Services Lines: 78 Message-ID: <35440D3F.F1B64D87@dontspam.cromnet.net.au> NNTP-Posting-Host: news AT marconi DOT dialix DOT com DOT au Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi, I'm going through a tutorial on c++. Am having trouble with the following example: It does not copy the input file to the file named "copy". The "copy" file is created but it contains nothing. The printer also does not print out the input file, it just prints the two lines: "This is the beginning of the printed copy." and "This is the end of the printed copy.". Could someone tell me what is wrong? // Chapter 1 - Program 4 - FSTREAM.CPP #include #include #include int main() { ifstream infile; ofstream outfile; ofstream printer; char filename[20]; cout << "Enter the desired file to copy ----> "; cin >> filename; infile.open(filename, ios::nocreate); if (!infile) { cout << "Input file cannot be opened.\n"; exit(1); } outfile.open("copy"); if (!outfile) { cout << "Output file cannot be opened.\n"; exit(1); } printer.open("PRN"); if (!printer) { cout << "There is a problem with the printer.\n"; exit(1); } cout << "All three files have been opened.\n"; char one_char; printer << "This is the beginning of the printed copy.\n\n"; while (infile.get(one_char)) { outfile.put(one_char); printer.put(one_char); } printer << "\n\nThis is the end of the printed copy.\n"; infile.close(); outfile.close(); printer.close(); return 0; } // Result of execution // // (The input file is copied to the file named "COPY") // (The input file is printed on the printer