C++/Development/command line
Output command line arguments
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, char** argv)
{
if (argc > 1) {
cout << argv[1];
for (int i = 2; i != argc; ++i)
cout << " " << argv[i];
}
return 0;
}
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;
}