class Foo {};
Foo foo;
namespace po = boost::program_options;
boost::program_options::options_description desc("Allowed options")
desc.add_options()
("foo", po::value<Foo>(&foo));
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
以上将最终尝试从std :: string&amp;做一个lex_cast。到Foo&amp;
有没有办法从const char *&amp;做一个lex_cast?为了Foo&amp;代替?
谢谢!
答案 0 :(得分:0)
您可以通过为Foo
:
std::istream& operator>>(std::istream &input_stream, Foo &foo) {
// read from input_stream into foo...
// if read fails, set failbit in input_stream...
return input_stream;
}