When using boost::program_options, how does one set the name of the argument?

后端 未结 6 1757
借酒劲吻你
借酒劲吻你 2021-02-01 18:02

When using boost::program_options, how do I set the name of an argument for boost::program_options::value<>()?

#include 

        
6条回答
  •  清歌不尽
    2021-02-01 18:52

    In the current version of boost (1.53) you don't need anymore to make your own class as Tim Sylvester proposed. It's possible to use : boost::program_options::typed_value. On which value_name can be configured.

    #include 
    #include 
    using boost::program_options::typed_value;
    using boost::program_options::options_description;
    
    int main(int argc, char **argv) {
        options_description desc("Usage");
    
        int someValue;
        auto someOption = new typed_value(&someValue);
        someOption->value_name("NUM");
        desc.add_options()
            ("some-option,s", someOption, "The option\n");
    
        std::cout << desc << std::endl;
        return 0;
    }
    

    Will display a configured argument name :

    Usage:
    -s [ --some-option ] NUM The option
    

提交回复
热议问题