Boost.Program_options provides a facility to pass multiple tokens via command line arguments as follows:
std::vector<int> nums;
po::options_description desc("Allowed options");
desc.add_options()
("help", "Produce help message.")
("nums", po::value< std::vector<int> >(&nums)->multitoken(), "Numbers.")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
However, what is the preferred way of accepting only a fixed number of arguments? The only solution I could come is to manually assign values:
int nums[2];
po::options_description desc("Allowed options");
desc.add_options()
("help", "Produce help message.")
("nums", "Numbers.")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("nums")) {
// Assign nums
}
This feels a bit clumsy. Is there a better solution?