CPP Find options passed from command line

To find the options passed from the command line in C++, you can use the argc and argv parameters in the main function. Here's an example of how to do it:

#include <iostream>

int main(int argc, char* argv[]) {
    std::cout << "Number of command line arguments: " << argc << std::endl;

    for (int i = 0; i < argc; ++i) {
        std::cout << "Argument " << i << ": " << argv[i] << std::endl;
    }

    return 0;
}

In this example, argc represents the number of command line arguments, and argv is an array of C-style strings containing the actual arguments. The first element in argv (argv[0]) is the name of the program itself.

The for loop iterates over each command line argument and prints its index and value using std::cout. You can modify this loop to perform different operations based on the specific command line options.

When you run this program with command line arguments, it will display the number of arguments and print each argument on a new line.

For example, if you compile and run the program with the command ./program option1 option2, the output will be:

Number of command line arguments: 3
Argument 0: ./program
Argument 1: option1
Argument 2: option2

This way, you can access and process the options passed from the command line in your C++ program.