Esteban,
Hi. If you remove 'ios::nocreate' from the line where you open infile, I
think you will find it works as planned, as follows:
infile.open(filename);
Hope this helps!
Chris
----- Original Message -----
From: "Esteban Crespí de Valldaura" <ec...@re...>
To: <dev...@li...>
Sent: 30 October 2000 23:00
Subject: [Dev-C++] get
> 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
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
>
|