/* 文件拷贝程序 即将src.dat拷贝到dest.dat 如果dest.dat原来就有,则原来的文件就会被覆盖 */ #include <iostream> #include <fstream> using namespace std; int main(int argc, char * argv []){ if (argc != 3){ cout << "File name missing!" << endl; return 0; } ifstream inFile(argv[1], ios::binary | ios::in); if (!inFile){ cout << "Source file open error." << endl; return 0; } ofstream outFile(argv[2], ios::binary | ios::out); if (!outFile){ cout << "New file open error." << endl; inFile.close(); return 0; } char c; while (inFile.get(c)) outFile.put(c); outFile.close(); inFile.close(); return 0; }
原文地址:http://blog.csdn.net/lionpku/article/details/45274105