Command Line Arguments in Cilk
Command-line arguments are a common way to parameterize execution of programs. For example, ./program arg1 arg2
uses arg1
and arg2
as arguments to the program
.
To experiment with command-line arguments, it’s best to compile the program first:
In Cilk, we use the standard C++ way of handling command-line arguments. The main
function receives two parameters: argc
(argument count) and argv
(argument vector). We use these to create vectors of strings for easier manipulation.
Note that Cilk is an extension of C++, so we can use all C++ standard library features. We’ve used std::vector
and std::string
for more convenient handling of the arguments.
The program demonstrates how to access all arguments (including the program name), how to access arguments without the program name, and how to access a specific argument by index.
Next, we’ll look at more advanced command-line processing with option parsing libraries available in C++.