Application of c ++ input/output stream

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.