Using command-line arguments : command line « Development « C++






Using command-line arguments

  
#include <iostream>
#include <fstream>
using namespace std;
int main( int argc, char *argv[] )
{
   if ( argc != 3 )
      cout << "Usage: copy infile outfile" << endl;
   else {
      ifstream inFile( argv[ 1 ], ios::in );
      if ( !inFile )
         cout << argv[ 1 ] << " could not be opened" << endl;

      ofstream outFile( argv[ 2 ], ios::out );
      if ( !outFile )
         cout << argv[ 2 ] << " could not be opened" << endl;

      while ( !inFile.eof() )
         outFile.put( static_cast< char >( inFile.get() ) );
   }

   return 0;
}
  
    
  








Related examples in the same category

1.Output command line arguments