file1.exe stream1.cpp stream2.cpp file1.cpp |
#include <iostream> #include <fstream> using namespace std; int main(int argc, char* argv[]) { if (argc<2) copyfile(cin, cout); //標準入力→標準出力 else { while(--argc>0) //コマンドラインで指定した数だけループ { ifstream i_f; //入力ファイルの宣言 i_f.open(*++argv); //入力ファイルのオープン if (!i_f) { cerr << "ファイル" << *argv << "オープンエラー\n"; return(1); } else { copyfile(i_f,cout); //入力→標準出力 i_f.close(); //入力ファイルのクローズ } } } return(0); } |
//File Copy routine void copyfile(istream& src, ostream& dst) { char ch; while(src.get(ch)) dst.put(ch); //一文字ずつコピー } |