How to use boost options_description with hex input?

I want to have two options for the program: the start address and the end address, so that the program parameters are as follows:

--start_address 0xc0000000 --end_address 0xffffffff 

Is it possible to take such hexadecimal input for options_description ? Should I treat the input as a string and convert them to hexadecimal values. I have this at the moment:

  po::options_description desc("Allowed options"); desc.add_options() ("help,h", "display this help message") ("path,p", po::value<std::string>(), "Executable file path") ("start_address,s", po::value<std::string>(), "Start address") ("end_address,e", po::value<std::string>(), "End address") ; 

Can boost::lexical_cast do such a conversion?

+7
c ++ boost boost-program-options
source share
1 answer

OK. I just found that I can use options_description to enter parameters, and then parse the parameters with std :: stringstream to convert to hex number as follows

  boost::uint32_t start_address; std::stringstream interpreter; interpreter << std::hex << vm["start_address"].as<std::string>(); interpreter >> start_address; 
+4
source share

All Articles