In contemporary C++ code, you should use the more robust array
(or vector
) objects to represent lists and tables of values. However, there are cases in which built-in arrays must be used, such as processing a program’s command-line arguments. You supply command-line arguments to a program by placing them after the program’s name when executing it from the command line. Such arguments typically pass options to a program. For example, on a Windows computer, the command
dir /p
uses the /p
argument to list the contents of the current directory, pausing after each screen of information. Similarly, on Linux or OS X, the following command uses the -la
argument to list the contents of the current directory with details about each file and directory:
ls -la
Command-line arguments are passed to main
as a built-in array of pointer-based strings (Section 8.10). Appendix F shows how to process command-line arguments.