我从How to accept empty value in boost::program_options得到了部分解决方案,它建议在那些可能有或没有参数的参数上使用implicit_value方法。 所以,我呼吁初始化“亮度”参数是这样的:
("brightness,b", po::value<string>()->implicit_value(""),
然后我迭代变量图和这是一个字符串的任何说法,我检查它是否是空的,如果是这样我打印的当前值。该代码看起来是这样的:
// check if we're just printing a feature's current value
bool gotFeature = false;
for (po::variables_map::iterator iter = vm.begin(); iter != vm.end(); ++iter)
{
/// parameter has been given with no value
if (iter->second.value().type() == typeid(string))
if (iter->second.as<string>().empty())
{
gotFeature = true;
printFeatureValue(iter->first, camera);
}
}
// this is all we're supposed to do, time to exit
if (gotFeature)
{
cleanup(dc1394, camera, cameras);
return 0;
}
UPDATE:这改变了上述语法,使用隐式的价值观,现在争论的时候,给的时候,一定是这样的形式:
./dc-ctl -b500
,而不是
./dc-ctl -b 500
希望这对别人有帮助。