0
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);

The above will eventually try to do a lex_cast from std::string& to Foo&

Is there a way for it to do a lex_cast from const char*& to Foo& instead?

Thanks!

MK.
  • 3,907
  • 5
  • 34
  • 46

1 Answers1

0

You can handle this by defining an istream operator for 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;
}
Fraser
  • 74,704
  • 20
  • 238
  • 215