//////////////////////////////////////////////////////// // // args.cpp // // Started 3/6/98 by Jeff Ondich // Last modified: 3/6/98 // // This program illustrates the use of command-line // arguments in C++ programs run on UNIX (and other // systems). // //////////////////////////////////////////////////////// #include int main( int argc, char *argv[] ) { // This prints out the command-line arguments in order. // Note that argc counts the command name itself as // one argument. for( int i=0; i < argc; i++ ) cout << "argv[" << i << "] = " << argv[i] << endl; // Here's how programs that use command-line arguments // often begin. For this example, I'll assume the program // is expecting two command-line arguments (in addition // to the command name): a dictionary file name and a // text file name. if( argc != 3 ) { cerr << "Usage: " << argv[0] << " dictionaryFile textFile" << endl; exit(0); } // Now move on with the rest of the program. cout << "Nice job. The right number of arguments." << endl; }