boost program options cannot accept hex number

I tried to supply a hex number to an unsigned long integer. But it fails. ("code", po::value<unsigned long>(), "Via pattern code") Error message: in option 'code': invalid option value '0x5A' Could you please let me if it is possible to input a hex form integer in the command line? Thanks, Peng

----- Original Message -----
From: "Peng Yu"
I tried to supply a hex number to an unsigned long integer. But it fails.
("code", po::value<unsigned long>(), "Via pattern code")
Error message: in option 'code': invalid option value '0x5A'
Could you please let me if it is possible to input a hex form integer in the command line?
Well, you can but it needs additional work (I am not the library author and cannot say if there is a better way). One way is to define your own validate overloads in boost::program_options: namespace boost { namespace program_options { template< class CharType, class Traits > void validate( boost::any& v, const std::vector< std::basic_string< CharType, Traits> >& xs, unsigned long*, long ) { // code to read the value from xs // Many iostream implementations support the auto-radix selection by clearing the basefield. But it is not portable } } } HTH, Sean
participants (2)
-
Peng Yu
-
Sean Huang