I declared a struct for some options that shall be filled by command line arguments or by reading an input file:
struct options {
int val1;
int val2;
bool val3;
}
Now I want to check for the correct number of arguments at execution of the program. Sure thing a
const int optionsSize = 3;
would do. But is there any adaptive way? What if I add another value into the struct and don't remember to increase the integer?
Why not add the options as specified into an std::vector<string> options
and use the options.size()
method to check the correct number. Then convert them to the proper datatype.
A more robust way of doing this kind of thing would be to use Boost Program Options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With