PEACE

和平

管理

main.cpp

 1 #include <iostream>
 2 #include <fstream>
 3 #include <stdlib.h>
 4 #include <windows.h>
 5 
 6 using namespace std;
 7 
 8 int main ( int argc, char* argv[] ) {
 9     if ( argc < 3 ) {
10         cout << "File Merge 1.0" << endl;
11         cout << "    Usage: fm <destination file> <source file>" << endl;
12         cout << "    e.g. fm app.exe 0_127.dat 128_138.dat" << endl;
13         return -1;
14     }
15     fstream dst0 ( argv[1], ios::out | ios::trunc );
16     if ( dst0.is_open() ) {
17         dst0.flush();
18         dst0.close();
19     } else {
20         cout << "Can not create <destination file> file." << endl;
21         return -1;
22     }
23     for ( int i = 2; i < argc; i++ ) {
24         fstream chk ( argv[i], ios::in | ios::binary );
25         if ( chk.is_open() ) {
26             chk.close();
27             continue;
28         }
29         cout << "Can not open <source file> file. \'" << argv[i] << "\'" << endl;
30         return -1;
31     }
32     fstream dst1 ( argv[1], ios::out | ios::binary | ios::app );
33     if ( dst1.is_open() ) {
34         for ( int i = 2; i < argc; i++ ) {
35             cout << "Processing " << i - 1 << " of " << argc - 2 << "..." << endl;
36             fstream src ( argv[i], ios::in | ios::binary );
37             if ( src.is_open() ) {
38                 while ( src.peek() != EOF ) {
39                     dst1.put ( src.get() );
40                 }
41                 src.close();
42                 dst1.flush();
43             }     else {
44                 cout << "Data loss on the way. Can not open <source file> file. \'" << argv[i] << "\'" << endl;
45                 break;
46             }
47         }
48         dst1.flush();
49         dst1.close();
50         cout << "File Merge completed." << endl;
51         return 0;
52     } else {
53         cout << "Can not open <destination file> file." << endl;
54         return -1;
55     }
56 }

附件1

posted on 2019-06-11 14:11  614616185  阅读(298)  评论(0编辑  收藏  举报