// Example of passing arguments into main // You may see the 'main' function in a C/C++ program with some // arugments, namely argc and argv[], these are two default parameters that // describe the command line arguments that invoke the program. argc is an integer // that tells you how many arguments there were and argv holds a pointer array // with the program name and command line tokens. The example below shows how it // can work. From the DOS prompt, just type in "argpassing hello world" and // you should see the following output: // The name used to start the program: argpassing // Arguments are: // 1: hello // 2: world // Also see: Appendix G that comes on the CD with the textbook #include #include using namespace std; int main(int argc, char *argv[]) { cout << "The name used to start the program: " << argv[0] << "\nArguments are:\n"; for (int i = 1; i < argc; i++) cout << setw( 2 ) << i << ": " << argv[i] << '\n'; return 0; }