boost-program-options

In Boost::Program_Options, how to set default value for wstring?

白昼怎懂夜的黑 提交于 2019-12-04 05:39:24
My code below did not work: wstring config_file; // Declare a group of options that will be // allowed only on command line po::options_description generic("Generic options"); generic.add_options() ("help,h", "produce help message") ("config,c", po::wvalue<wstring>(&config_file)->default_value(L"DXDrv.cfg"), "name of a file of a configuration.") ; The compilation failed with error: d:\repo\a4x_ext\minidxdriver\testapp\configparser\boost\lexical_cast.hpp(1096) : error C2039: 'setg' : is not a member of 'boost::detail::lexical_stream_limited_src<CharT,Base,Traits>' Long-winded explanation: This

using hashmark in program options value (ini file)

六眼飞鱼酱① 提交于 2019-12-04 02:16:01
问题 I have some trouble reading from an ini file using boost program options. The problem is a key which contains hashmarks (simplyfied example): [section] key="xxx#yyy" Retrieving the key, returns "xxx", which is because the hashmark seems to be interpreted as start of a comment and therefore the rest of the line is skipped. Unfortunately I cannot substitute the '#' by some other character because the value is a regular expression. I didn't find a way to quote the hashmark and would prefer not

Cannot find C++ library when linking, error compliling the `boost::program_options` example

∥☆過路亽.° 提交于 2019-12-03 22:56:40
I am trying to compile the multiple_sources.cpp to compile on my computer. I am running Xubuntu Lucid Lynx fully updated. It will compile without issue with g++ -c multiple_sources.cpp but when I try to link and make an exectuable with g++ multiple_sources.o I get: multiple_sources.cpp:(.text+0x3d): undefined reference to `boost::program_options::options_description::m_default_line_length' multiple_sources.cpp:(.text+0x87): undefined reference to `boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&,

Sets of mutually exclusive options in boost program options

强颜欢笑 提交于 2019-12-03 20:37:17
问题 My program ( prog.exe ) supports the following four flags: -P , -p , -b and -s . However: -b and -p must be specified together, constitute a set, and have numeric values e.g. -b 42 -s cannot be specified with the above set, and vice versa -P is mandatory in both cases As such prog.exe can only be run as either prog.exe -P -s or prog.exe -P -b -42 -p 8 Is there a way to specify the above sets of mutually exclusive command line options in boost program options? 回答1: You should start with a few

boost::program_options and multiple sections in ini-file

大城市里の小女人 提交于 2019-12-03 16:52:01
I'm trying to get boost::program_options to read a ini file with multiple sections: [slave] address=localhost port=1111 [slave] address=192.168.0.1 port=2222 Is there any solution? Thanks in advance! There are a few solutions to this problem. While it may initially appear that this should be an easy task, it is often fairly involved. This is because sections are roughly equivalent to namespaces; sections are not equivalent to objects. [slave] address=localhost port=1111 [slave] address=192.168.0.1 port=2222 The above configuration has a single slave namespace, that contains two address values

Boost Custom Validator for Enum

谁说我不能喝 提交于 2019-12-03 15:03:13
问题 I am trying to validate command line input to an Enum that I've defined, but get compiler errors. I have used Handle complex options with Boost's program_options as an example to work from. namespace po = boost::program_options; namespace Length { enum UnitType { METER, INCH }; } void validate(boost::any& v, const std::vector<std::string>& values, Length::UnitType*, int) { Length::UnitType unit; if (values.size() < 1) { throw boost::program_options::validation_error("A unit must be specified"

boost program_options multiple values problem

杀马特。学长 韩版系。学妹 提交于 2019-12-03 07:58:11
So I'm working off one of the examples for Boost program_options library, and I wanted to try setting a default value for one of the multiple-values/ vector-values, but it doesn't seem to work. As I think is suggested here to work . What I've modified is on about line 40: po::options_description config("Configuration"); config.add_options() ("optimization", po::value<int>(&opt)->default_value(10), "optimization level") ("include-path,I", o::value< vector<string> >()->default_value(vector<string>(),"SOMETHING")->composing(), "include path") ; When I compile this small change, I expect that when

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

谁说我不能喝 提交于 2019-12-03 06:32:43
问题 When using boost::program_options , how do I set the name of an argument for boost::program_options::value<>() ? #include <iostream> #include <boost/program_options.hpp> int main() { boost::program_options::options_description desc; desc.add_options() ("width", boost::program_options::value<int>(), "Give width"); std::cout << desc << std::endl; return 0; } The above code gives: --width arg Give width What I want is to replace the arg name with something more descriptive like NUM : --width NUM

Boost Custom Validator for Enum

不打扰是莪最后的温柔 提交于 2019-12-03 04:45:34
I am trying to validate command line input to an Enum that I've defined, but get compiler errors. I have used Handle complex options with Boost's program_options as an example to work from. namespace po = boost::program_options; namespace Length { enum UnitType { METER, INCH }; } void validate(boost::any& v, const std::vector<std::string>& values, Length::UnitType*, int) { Length::UnitType unit; if (values.size() < 1) { throw boost::program_options::validation_error("A unit must be specified"); } // make sure no previous assignment was made //po::validators::check_first_occurence(v); // tried

How to parse comma separated values with boost::program_options?

ⅰ亾dé卋堺 提交于 2019-12-01 22:12:52
问题 I need to parse cmd like -value=str1,str2,str3 using boost::program_options . I've found exactly the same question but it's not working anymore (with boost 1.55 and 1.56). I've tried to define my own class and mapper but no luck: namespace po = boost::program_options; desc.add_options() ("mattr", po::value<lli::CommaSeparatedVector>(&MAttrs), "Target specific attributes (-mattr=help for details)"); namespace lli { class CommaSeparatedVector { public: // comma separated values list std::vector