2010-04-30 13 views
7

मैं इस कार्यक्रम पर काम करने के आरंभ पता और समाप्ति पते के लिए दो विकल्प हैं करना चाहते हैं ताकि कार्यक्रम विकल्प इस प्रकार हैं:हेक्सडेसिमल इनपुट के साथ बूस्ट विकल्प_डिस्क्रिप्शन का उपयोग कैसे करूं?

--start_address 0xc0000000 --end_address 0xffffffff 

क्या यह संभव है options_description ऐसे हेक्स इनपुट लेने के लिए? क्या मुझे इनपुट को स्ट्रिंग के रूप में मानना ​​है और उन्हें हेक्स मानों में परिवर्तित करना है। मैं इस समय इस राशि:

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

boost::lexical_cast इस तरह के एक रूपांतरण कर सकता हूँ?

उत्तर

4

ठीक है। बस की खोज की मैं विकल्प डालने के लिए options_description उपयोग कर सकते हैं और फिर std :: stringstream का उपयोग कर एक हेक्स संख्या में बदलने के लिए के रूप में

boost::uint32_t start_address; 
    std::stringstream interpreter; 

    interpreter << std::hex << vm["start_address"].as<std::string>(); 

    interpreter >> start_address; 
+2

इस प्रकार विकल्प पार्स ... लेकिन आप अपवाद होता है कि जब आप की कोशिश से कैसे निपटते हैं डिफ़ॉल्ट पार्सिंग होने के लिए? – aardvarkk

संबंधित मुद्दे