Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main() {
- char file1[20], file2[20], file3[20], ch;
- long i, n, limit;
- system("cls");
- // Taking the name of the files as input
- cout << "Enter the input file name: ";
- cin >> file1;
- cout << "Enter the output file 1 name: ";
- cin >> file2;
- cout << "Enter the output file 2 name: ";
- cin >> file3;
- ifstream fp1;
- ofstream fp2;
- ofstream fp3;
- // Opening the file
- fp1.open(file1, ios::binary);
- fp2.open(file2, ios::binary);
- fp3.open(file3, ios::binary);
- // Moving the file object to the end of the file
- fp1.seekg(0, ios::end);
- // To get the last byte position
- n = fp1.tellg();
- // Calculating limit
- limit = n / 2;
- // Moving file object to the begining of the
- // file
- fp1.seekg(0, ios::beg);
- // To copy data from the input file to the
- // output file
- for(i = 1; i <=n ; i++){
- ch = fp1.get();
- if(i <= limit){
- fp2.put(ch);
- }
- else {
- fp3.put(ch);
- }
- }
- // Closing the files
- fp1.close();
- fp2.close();
- fp3.close();
- // Displaying the size of the file in bytes
- cout << "\nFile copy is over, Number of bytes copied = "
- << n << endl;
- cout << "Size of <" << file2 << "> = " << limit << " bytes\n";
- cout << "Size of <" << file3 << "> = " << (n - limit) << " bytes" << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment