Boost logo

Boost Users :

Subject: Re: [Boost-users] Lexical_cast and hex number
From: Jeroen Habraken (vexocide_at_[hidden])
Date: 2010-12-03 07:21:49


On 2 December 2010 22:27, Claude <clros_at_[hidden]> wrote:
> 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<>?

There's another option I've been working on, construe_cast, which can
be found here: It's a
replacement for lexical_cast which I hope will make it into boost one
day. The main difference is that whilst lexical_cast uses iostreams
for its conversion, construe_cast is based off of boost.spirit. This
means it's considerable faster at run-time and I've added support for
tags some time ago, thus you can use:

boost::construe_cast<unsigned int, boost::construe::tag::hex>("2c4")

At the moment there is no support for "0x2c4" but that should be added
later today (the tag::hex will then support "0x2c4", "0X2c4" as well
as "2c4"). Documentation is still on the todo-list and something I
hope to get to soon, but if you have any questions don't hesitate to
ask them.

Jeroen Habraken

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at