Working With Command-Line Arguments
When we run a program from the command line, the positional arguments are those arguments whose purpose is identified by their position on the command line.
For example, the cp
(copy) command in Unix accepts two positional
arguments: the name of the file to copy from and the name of the
file to copy into. In the command cp -p foo bar
you are asking the
program to copy foo
to bar
using the -p
(preserve attributes)
option.
Within the main
function of a C++ program, any positional
arguments from the command line are stored in the argv
argument,
which you can access as an array. argv[0]
will always be the name
of the program that is running, and the rest of the elements of
argv
will be the positional arguments. The argc
argument of
main
gives the size of the argv
array.
(When logged in, completion status appears here.)