[ create a new paste ] login | about

Link: http://codepad.org/ivXJsWrE    [ raw code | fork ]

C++, pasted on Jul 23:
//入力ファイルと出力ファイル名をコマンドラインから入力してコピーするプログラム

#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>

using namespace std;

int main(int argc, char *argv[]){
	if(argc < 2){
		cout << "コマンドライン引数が不正です" << endl;
		assert(0);
	}
	
	string SrcFilename = argv[1];
	string DestFilename = argv[2];//Destination

	//入力
	ifstream InputFile(SrcFilename.c_str(),ifstream::binary);

	if(!InputFile){
		cout << "コピー元ファイルが見つかりません" << endl;
		assert(0);
	}

	InputFile.seekg(0,ifstream::end);//末尾へ
	int FileSize = static_cast<int>(InputFile.tellg());
	InputFile.seekg(0,ifstream::beg);//頭へ

	char* File = new char[FileSize];
	InputFile.read(File,FileSize);

	//出力
	ofstream OutputFile(DestFilename.c_str(),ifstream::binary);
	if(!OutputFile){
		cout << "コピー先ファイル名が不正です" << endl;
		assert(0);
	}
	OutputFile.write(File,FileSize);

	delete[] File;

	cout << "正常終了" << endl;
	return 0;
}


Create a new paste based on this one


Comments: