// バイナリファイルの入出力 // 1バイトずつ読み込んで書き込みます. //-------------------------------------------------------------------- // Name // stream02.cpp // // Description // 1バイト単位にファイルコピーを行います // #include <iostream> #include <fstream> using namespace std; int main( int argc, char *argv[] ) { if ( argc != 3 ) { cout << "usage: stream02 input_file output_file" << endl; return 1; } ifstream in( argv[1] , ios::in | ios::binary ); // 入力ストリーム if ( !in ) { cout << "can't open file " << argv[1] << endl; return 1; } ofstream out( argv[2], ios::out | ios::binary );// 出力ストリーム if ( !out ) { cout << "can't open file " << argv[2] << endl; return 1; } char c; while ( in.get( c ) ) { out.put( c ) ; } // クローズ in.close( ); out.close( ); return 0; } // // バイナリモードを使用する時は、ファイルオープン時に // openmode の ios::binary を指定します。 //