小编Mat*_*zer的帖子

在使用boost程序选项时,希望允许多次指定选项.现在我多次出现

我正在使用boost program_options 1.50.0

我想为我的程序foobar提供以下内容 foobar --debug 2 --debug 3

从boost program_options代码中,有一个示例regex.cpp,它显示了创建新类型并为该类型创建验证器.
我试过了,但它确实有效,但现在我不能使用其他一些add_options()typed_value选项,比如default_value,composing等.

这是我到目前为止尝试的内容:

    #include <boost/program_options.hpp>

    using namespace boost;

    using namespace boost::program_options;

    #include <iostream>
    using namespace std;
    struct lastmultioccurrenceint {
        public:
         lastmultioccurrenceint(int n) : n(n) {}
         int n;
    };    

void validate(boost::any& v, 
                  const std::vector< std::string >& xs, 
                  //const std::vector< std::basic_string<charT> >& xs, 
                  lastmultioccurrenceint* , int)
    {
        using namespace boost::program_options;

        cerr << "IN VALIDATE" << endl;
        //validators::check_first_occurrence(v);
        string s = validators::get_single_string(xs);
        if (!v.empty()) {
            cerr << "\tPRINTTING MULTIOCCURENCE WARNING, allowing v to …
Run Code Online (Sandbox Code Playgroud)

c++ boost custom-validators boost-program-options

8
推荐指数
1
解决办法
3982
查看次数