Boost logo

Boost Users :

Subject: Re: [Boost-users] Lexical_cast and hex number
From: 陳韋任 (chenwj_at_[hidden])
Date: 2010-12-02 19:17:41


Hi,

> It is possibile to transform a string representing a hexadecimal number in
> the format "0xnumber" or "number" (without "0x") in an integer with
> lexical_cast<>?

  In my experience, lexical_cast<> cannot transform a string
representing a hexadecimal number into an integer.

  unsigned int x = lexical_cast("0x0badc0de"); // throw bad_lexical_cast

  Instead of using lexical_cast<>, you should use stringstream to do
this kind of transform. For example, see the link below:

  http://stackoverflow.com/questions/1070497/c-convert-hex-string-to-signed-integer

Regards,
chenwj
 

-- 
Wei-Ren Chen (陳韋任)
Tel:886-2-2788-3799 #1667
Parallel Processing Lab, Institute of Information Science,
  Academia Sinica, Taiwan (R.O.C.)

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net