/*
文件拷貝程序
即將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;
}
C++文件操作(二)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.