这是我的问题:
使用lib BOOST(C ++)中的program_options,我有这种奇怪的行为:
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
using namespace boost;
namespace po = boost::program_options;
#include <iostream>
using namespace std;
int main(int ac,char* av[])
{
int cost_function_param;
po::options_description desc("Allowed options");
desc.add_options()
("cost-function", po::value<string>()->default_value("WA"), "Cost function (W: wirelength, A: area ratio, C: cut; [WA, WAC, WC, AC]")
("cost-function-param", po::value<int>(&cost_function_param)->default_value(0), "Specify the parameter of the cost function. Implemented is \"C\" only for now.")
;
po::variables_map vm;
try {
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << desc << std::endl;
return -1;
}
}
案例#1:
./Debug/partition --cost-function-param 200
没有错误。
案例#2:
./Debug/partition --cost-function-param 2000 --cost-function WAC
或
./Debug/partition --cost-function WAC
结果:
ERROR: ambiguous option cost-function
Allowed options:
--cost-function arg (=WA) Cost function (W: wirelength, A: area ratio,C: cut; [WA, WAC, WC, AC]
--cost-function-param arg (=0) Specify the parameter of the cost function. Implemented is "C" only for now.
有人有解释吗?谢谢!