我已经多次尝试让这个工作无济于事。该程序可以编译,但我能想到的用于提供给程序的每种时间戳格式都是无效的。
#include <boost/program_options.hpp>
#include <boost/optional.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
#include <string>
using namespace boost::program_options;
using namespace std;
int main(int argc, const char** argv) {
boost::posix_time::ptime forceDate;
boost::optional<boost::posix_time::ptime> forceDateOptional;
options_description descr("Options");
descr.add_options()
("force-date,a", value(&forceDate)->value_name("<date>"), "...");
try {
variables_map args;
store(command_line_parser(argc, argv).options(descr).run(), args);
notify(args);
cout << "Done." << endl;
return 0;
} catch (std::exception& e) {
cerr << e.what() << endl;
return 1;
}
}
编译g++ -I /usr/local/include -L /usr/local/lib -lboost_program_options -lboost_system x.cpp
并运行./a.out --force-date 2012-01-03
.
这是引发的异常的错误:
the argument ('2012-01-03') for option '--force-date' is invalid