[Html] view plaincopy
# Include <iostream>
# Include <fstream>
# Include <stdlib. h>
Using namespace std;
Class Copy_file
{
Public:
Copy_file ();
~ Copy_file ();
Void Copy_files ();
Void in_file ();
Void out_file ();
Protected:
Private:
Fstream infl;
Fstream outf;
Char file1 [20];
Char file2 [20];
};
Copy_file: Copy_file ()
{
Cout <"Enter the file name :";
Cin> file1;
Infl. open (file1, ios: in | ios: binary );
If (! Infl)
{
Cout <"the original file cannot be opened:" <file1 <endl;
Abort ();
}
Cout <"Enter the destination file name :";
Cin> file2;
Outf. open (file2, ios: in | ios: out | ios: binary );
If (! Outf)
{
Cout <"the target file cannot be opened :";
Abort ();
}
}
Copy_file ::~ Copy_file ()
{
Infl. close ();
Outf. close ();
}
Void Copy_file: Copy_files ()
{
Char ch;
Infl. seekg (0 );
Infl. get (ch );
While (! Infl. eof ())
{
If (ch> = 'A' & ch <= 'Z ')
Outf. put (ch );
Infl. get (ch );
}
}
Void Copy_file: in_file ()
{
Char ch;
Infl. close ();
Infl. open (file1, ios: in | ios: binary );
Infl. get (ch );
While (! Infl. eof ())
{
Cout <ch;
Infl. get (ch );
}
Cout <endl;
}
Void Copy_file: out_file ()
{
Char ch;
Outf. seekp (0 );
Outf. get (ch );
While (! Outf. eof ())
{
Cout <ch;
Outf. get (ch );
}
Cout <endl;
}
Int main ()
{
Copy_file cf;
Cf. Copy_files ();
Cout <"original file content:" <endl;
Cf. in_file ();
Cout <"target file content:" <endl;
Cf. out_file ();
System ("pause ");
Return 0;
}
Author: OPK625153475