/*★ file2.CPP ファイルコピーのサンプルプログラム 前田 稔 ★*/ #include #include using namespace std; //File Copy routine void copyfile(istream& src, ostream& dst) { char ch; while(src.get(ch)) dst.put(ch); //一文字ずつコピー } int main(void) { ifstream i_f; //入力ファイルの宣言 ofstream o_f; //出力ファイルの宣言 i_f.open("file2.cpp",ios::in); if (!i_f) { cerr << "ファイル" << "file2.cpp" << "オープンエラー\n"; return(1); } o_f.open("w.txt",ios::out); if (!o_f) { cerr << "ファイル" << "w.txt" << "オープンエラー\n"; return(1); } copyfile(i_f,o_f); i_f.close(); //入力ファイルのクローズ return(0); }