|
From: <ec...@re...> - 2000-10-30 23:01:22
|
Hello, I am new to C++.
I am following a tutorial in wich it appears the following code (wich makes
a copy of a file):
#include <iostream.h>
#include <fstream.h>
#include <process.h>
void main()
{
ifstream infile;
ofstream outfile;
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);
}
char one_char;
while (infile.get(one_char)) {
outfile.put(one_char);
cout.put(one_char);
}
infile.close();
outfile.close();
}
It should create a copy of the original file into the file "COPY". The
program compiles and runs properly but the file COPY is empty (it exists but
has 0 bytes), what is wrong?
thanks. Esteban
|