1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include<iostream> #include<fstream> #include<cstring>
using namespace std;
int main(int argc, char* argv[]) { using namespace std; if (argc < 3){ cout << "filename missed" << endl; return 0; } ifstream in(argv[1], ios::binary | ios::in); if (!in){ cout << "source file open failed" << endl; return 0; } ofstream out(argv[2], ios::binary | ios::out); if (!out) { cout << "New file open error." << endl; in.close(); return 0; } if (strcmp(argv[1], argv[2])==0) { cout << "the src file can't be same with dst file" << endl; exit(EXIT_FAILURE); } char buf[2048]; while (in) { in.read(buf, 2048); out.write(buf, in.gcount()); } in.close(); out.close(); }
|